-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unsubscribe call behaves unexpectedly #34
Comments
@tsgautier Sorry about the trouble! Looking at this right now.... |
no problem - surprisingly, nextTick works, but leaves the code susceptible to multiple deliveries, so a flag is required to protect that, here's an approximation: p = require 'postal'
postal = new p()
channel = postal.channel ''
delivered = false
subscription1 = channel.subscribe 'test', ->
return if delivered
delivered = true
console.log '1 received message'
process.nextTick -> subscription1.unsubscribe()
subscription2 = channel.subscribe 'test', ->
console.log '2 received message'
channel.publish 'test'
channel.publish 'test' |
…ncorrectly handling a mutating array of subscribers as it iterated over them. I also fixed the once() call to return the instance.
This issue should be resolved - sorry for the woes. I should know better than to iterate over mutating arrays. :-) One other thing, you actually don't need the
The node module just returns a factory function that optionally takes underscore as a dependency (it requires underscore for you if it's not passed). This approach is used so that postal and any add-ons are all accessing the same instances of modules... Let me know if you run into any other issues. Thanks! |
I'm trying to implement something like a one-time listener. However, unsubscribing at certain times behaves unexpectedly. Here's some code:
The above code behaves as expected, the output is as follows:
However, to implement the "one-time" I did something like this:
This outputs:
Which is pretty unexpected. Somehow the subscription1.unsubscribe() is unsubscribing both subscriptions.
The text was updated successfully, but these errors were encountered: