k-yle / sACN

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

Callback throws Error: addMembership EADDRNOTAVAIL #21

Closed schw4rzlicht closed 4 years ago

schw4rzlicht commented 4 years ago

When calling new Receiver() with an interface that doesn't exist, Socket.addMembership() throws Error: addMembership EADDRNOTAVAIL which is not catchable since it happens in the callback.

Wouldn't it be a better idea to add a start() method to Receiver which returns a promise so we could handle the error properly?

k-yle commented 4 years ago

I've added a new "error" event which is emitted. You can listen using

sACN.on('error', (err) => {
  // trigged if there is an internal error (e.g. the supplied `iface` does not exist)
});

I prefer this paradigm over an async start() method since this whole module is built around nodejs's EventEmitter.