On Feb 25, 2012, at 4:57 PM, Mark Volkmann wrote:
> On Sat, Feb 25, 2012 at 9:47 AM, Rambo <[email protected]> wrote:
>> Just a simple question before I try to explain the problem:
>> 
>> Do every synchronous statement inside functions finish execution before the
>> next event loop?
> 
> Yes.
> 
>> Example:
>> object.on('event', function() {
>>     console.log('async')
>> });
>> function test() {
>>     sync1();
>>     sync2();
>> }
>> test();
>> 
>> Could the event loop execute a callback added as an event listener between
>> sync1 and sync2 call?
> 
> No. I sure hope nobody disagrees with me. If I'm wrong then I badly
> misunderstand what's going on in Node.

Node's EventEmitter.emit() is synchronous, so if sync1 contains anything like 
this:

function sync1 () {
  object.emit('event', 'data');
}

then the object.on('event', handler) handler above will be executed between the 
sync1 and sync2 calls above.

IMHO, as a sync .emit() may produce right on the spot any Series of Unfortunate 
Events, it ought to be async instead, and, for the brave hearts who may want 
it, there ought to be an .emitSync() too.

One could always do a process.nextTick(function(){ object.emit(blah,blah) }), 
but async should be the norm, not the exception, imho.
-- 
Jorge.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to