-
-
Save pvdz/f33a51dc7189d98efe23 to your computer and use it in GitHub Desktop.
// PubSub.subscribe('foo', function(name, value) {}); | |
PubSub.publish('foo', 'bar'); | |
PubSub.subscribe('foo', function(name, value) {}); |
My expectation is that .publish(
only queues the event and nothing else. Then when the code/browser yields and PubSub
gets a chance to fire events I expect it to look for subscribers and emit to all subscribers at that point.
Right now it seems to collect all subscribers at call time. It won't find any so the event fizzles.
That is correct, right? Or is my test setup wrong?
Your test is probably correct, and I think I now understand your expectation. I think that it would be the most common expectation for this scenario and that we should update PubSubJS to match it.
This is similar to resolving/rejecting a promise and registering another .then
or .otherwise
after doing so. The guaranteed async behavior made me think pubsub would follow the same line.
The main difference is that I don't expect pubsub to fire events retroactively for events registered after a yield. Don't get me wrong there :) But if an event hasn't fired yet, it should fire for all events that are registered up until the point where it fires, even if there weren't any events at the time of calling .publish
.
So basically, I suspect a (imo) bug in where subscribers are collected. I think pubsub fizzles the event because there are no subscribers for it at call time. I'm sure you can confirm/reject this :)
Oh. Github didn't update. Great, should I file a ticket?
Yeah, a ticket would be great!
Thanks!
Is your expectation that only the first subscriber be called?