Closed ronag closed 3 years ago
If sender "is closed" you cannot do anything with it - it should throw in that case. So either keep track of when sender closes, or handle the exception. If sender is closed then app.publish will have the same behavior (send to all but sender is the same if sender is closed).
If sender "is closed" you cannot do anything with it - it should throw in that case.
Looking at the code I'm not sure that's the case?
If sender is closed then app.publish will have the same behavior (send to all but sender is the same if sender is closed).
So you suggest something like:
if (sender) {
try {
sender.publish(subscription.id, subscription.message)
} catch (err) {
if (err.code == WHAT_CODE_???) {
app.publish(subscription.id, subscription.message)
} else {
throw err
}
}
} else {
app.publish(subscription.id, subscription.message)
}
https://github.com/uNetworking/uWebSockets.js/blob/master/src/WebSocketWrapper.h#L29
No I would prefer keeping track of when sender is closed, but otherwise, yes.
Thanks!
I have a use case where a socket sends a message and the server is supposed to broadcast it to all others:
However, if the
sender
is closed then this code will actually not send the message to anyone. What's the best way to handle this?Wouldn't it better to have a different signature on
app.publish
? Something like: