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?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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?