-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Initialization race condition. #1
Comments
Do you see this as a documentation issue? The way I expect sparkles to be used is like so: var sparkles = require('sparkles');
var b = require('./b');
var i = sparkles('my-namespace');
i.on('foo', fn);
i.emit('foo', 'a'); |
Clear docs would help, but I think the require and initialize on one line is pretty common for this sort of thing. Can a namespace's ee be added to the global store the first time it is created? |
I was trying to keep the global cleaned up when all listeners are removed but I could leave the namespace around if I am going to implement #2 |
That's a good idea, but I think it would lead to unexpected behavior. Things like a global broadcast channel, where one module periodically issues events through the entire lifecycle of the app, but other modules add and remove listeners asynchronously. It would be hard to tell when all of a sudden you get a new event emitter that isn't receiving the events the original module is broadcasting, just because someone happened to remove the last listener. Maybe add a |
That's a good idea. I basically added that into glogg and it would be nice to be exposed through sparkles instead. |
Ahh, nice. You could put it on the ee itself, and remove all listeners then null out the global reference. I like it. |
Thoughts on 834e409 ? does it solve this? |
Looks great, solves all my concerns. |
Given modules a
and b:
You end up with references to two different event emitters, and only 'a' gets logged. If in a you add your listener before requiring b, they are the same event emitter and work as expected.
The text was updated successfully, but these errors were encountered: