If you think about how events are used, it's really important that
emit() is synchronous.

If I do `foo.on('bar', myFunction)`, then I want myFunction to be
called *right when 'bar' happens*, not some time *after* 'bar' has
happened.

This is especially important when you think about a http request.  We
parse the headers, and then emit the 'request' or 'response' event and
call your handler right away, before anything else happens to it.  If
we waited until later, it'd be in a weird buffering state, and who
knows what might have happened in the meantime.

Of course, `emit()` might be called at any arbitrary time.  So
`foo.on('bar', fn)` doesn't wait around blocking until `'bar'` is
emitted.  The emission could come on nextTick, or hours later.  But,
WHEN 'bar' is emitted, fn is called right away in that exact moment.


On Fri, Jan 11, 2013 at 9:31 AM, Eric Chaves <[email protected]> wrote:
> Thanks!
>
> 2013/1/11 Dan Milon <[email protected]>
>>
>> danmilon
>
>
>
> --
> 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

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