-
Notifications
You must be signed in to change notification settings - Fork 4
Description
In 2.x.x when "emit" is called the handler functions are executed immediately and the emit returns after the handlers are finished.
Other option for this is to move them on the top of the JS's event queue with following convention (See page 33 in Hands on Node.js by Pedro Teixeira or http://stackoverflow.com/q/779379/638546).
setTimeout(function () {
handler(...);
}, 0); // Note the zero.
With that the handlers are called not before the event queue has progressed to the timeouts.
Having or not having this makes a big difference to the meaning of "emit". If synchronous, emit equals to calling a bunch of functions. On the other hand if asynchronous, emit equals to being a trigger for bunch of functions but not blocked by their execution.
Which one, synchronous or asynchronous, should be the default? Should the other be implemented at all? By following Node.js's conventions the solution would be having "on" and "onSync" (See http://nodejs.org/api/fs.html).