0

I'm trying to run this code in node REPl

var E = require('events').EventEmitter;
var e = new E(); //controller

e.on('msg', function(){ console.log(1) }); //handling

(function(){

  console.log(0);
  e.emit('msg');
  console.log(2);

}()); //self-execution

so it gives in console

0
1
2

does it mean that event emitting is synchronous and that code is some-way equal to:

(function(){

  console.log(0);
  console.log(1);
  console.log(2);

}()); //self-execution
IvanM
  • 2,913
  • 2
  • 30
  • 30

1 Answers1

1

The emitter is synchronous indeed.

But pay attention, if you are going to code asynchronous statements in your listener it will affect your code.

lastboy
  • 566
  • 4
  • 12