No events are being emitted in sync1().
It is worst than you think, the real thing is:
var list = [1,2,3];
object.on('event', f1);
function f1() {
list.forEach(function(item) {
if (item == 1) console.log('before')
sync1(); // item is not being modified anywhere
if (item == 1) console.log('after') // this SOMETIMES gets called!!!
});
}
On Saturday, February 25, 2012 1:32:27 PM UTC-3, Martin Cooper wrote:
>
> On Sat, Feb 25, 2012 at 7: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?
> >
> > 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? if so, when does sync2 get executed, before or
> after
> > the callback?
>
> The event loop, no, but remember that the event mechanism itself is
> not inherently asynchronous. If something in sync1() is calling
> object.emit('event'), then the callback will be called right there and
> then; the event loop is not involved.
>
> --
> Martin Cooper
>
>
> > Thanks.
> >
> > --
> > 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