serialport / node-serialport

Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
https://serialport.io
MIT License
5.8k stars 1.01k forks source link

Implement Duplex destroy #2831

Open rotu opened 3 months ago

rotu commented 3 months ago

Previously, there was no way to close a port reliably with this API. If you open a port, trying to .close before it's done opening would throw an error and leave the underlying port open. If you used node's .destroy(), stream.addAbortSignal(), or [Symbol.asyncDispose], the underlying port would remain in an open state.

This change implements the Duplex.destroy method. This is different from .close in that once a SerialPortStream is destroyed, it cannot be opened again.

rotu commented 3 months ago

@reconbot Could you please take a look at this?

rotu commented 3 months ago

@reconbot, could you please let me know if this PR is in the right direction? Or if there's some other intended way to clean up a SerialPort object?

jichu4n commented 3 months ago

+1 - would also like to see this fix (or similar) merged, as the current behavior in #2776 is quite tricky to work around.

rotu commented 1 month ago

for your consideration, @reconbot

rotu commented 1 month ago

@HipsterBrown maybe you can help?