k-yle / sACN

💡 🎭 Send & Receive sACN data (DMX over IP) in node.js
https://npm.im/sacn
Apache License 2.0
28 stars 12 forks source link

Add optional callback to Receiver.close() #23

Closed schw4rzlicht closed 4 years ago

schw4rzlicht commented 4 years ago

I'd like to propose a change to the Receiver.close() function. The underlying Socket.close() function accepts an optional callback which gets called when the socket is eventually closed.

Since reconfiguring the receiver is not possible, we need to close it first, create a new instance and start it again. Although possible to reconfigure universes to listen to it would be nice to be able to wait for Socket.close(). As of now there is no possibility to wait for the socket to be closed, therefore when calling Receiver.start() on a new instance the port is still occupied (although using reuseAddr: true for that matter...).

This could also be implemented using events but since Socket.close() already offers that feature I figured that would be the easiest way.

k-yle commented 4 years ago

Looks good, thank you!