Awesome! Thanks, Rick.

-Chaoran

On Friday, October 4, 2013 3:54:50 PM UTC-5, Rick Waldron wrote:
>
>
>
>
> On Fri, Oct 4, 2013 at 12:09 PM, Chaoran Yang 
> <[email protected]<javascript:>
> > wrote:
>
>> Questions 1: Are event listeners always invoked synchronously?
>>
>> For example, If I do:
>>
>> event.on("end", function() {
>>   console.log("end");
>> });
>> event.emit("end");
>> event.removeAllListeners();
>>
>> Does this code always prints "end" every time?
>>
>
> Yes, the current implementation is synchronous and yes that's ok (and 
> totally normal/expected)
>
> console.log(1);
> emitter.on("end", function() {
>   console.log(3);
> });
> console.log(2);
> emitter.emit("end");
> console.log(4);
> emitter.removeAllListeners();
> console.log(5);
>
> Will output: 
> 1
> 2
> 3
> 4
> 5
>
>
>
>  
>
>>
>> Question 2: Are event listeners always invoked in the order of they are 
>> attached?
>>
>> For example, if I do:
>>
>> event.on('end', function() {
>>   console.log('end');
>> });
>> event.on('end', function() {
>>   event.removeAllListeners();
>> });
>> event.emit('end');
>>
>> Does this code always prints "end" every time?
>>
>
> Yes, this is documented: 
> http://nodejs.org/api/events.html#events_emitter_addlistener_event_listener
>  
>
> Rick
>
>

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to