You are reading a single comment by @DrAzzy and its replies. Click here to read the full conversation.
  • Aaah... that's awkward...

    What about catching the most common case? Once a character has been read from or written to the Espruino via USB, you could set a flag.
    If that flag hasn't been set, then the computer hasn't sent anything to it or read anything from it - so we can assume that it's not "connected" to the USB serial, and thus we shouldn't block waiting for the buffer to empty.
    If that flag has been set, we use the behavior we have now.
    Maybe add a USB.disconnect() (or some other name) function to unset the flag - so the IDE could send that when you cleanly disconnect, so then it would not block waiting for the computer to read bytes from it until the computer again sent or read something from it?

About

Avatar for DrAzzy @DrAzzy started