Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
By itself, EventEmitter.emit is a synchronous function, which may surprise many.
process.on('ev', function() {
console.log('ev');
});
(function() {
console.log('a');
process.emit('ev');
console.log('b');
} ());
//a
//ev
//b
process.on('ev', cb)
was called not so trivially and in several places in asynchronous code, I would not advise you to even try to figure out which one cb
will be called first. I'm not saying that you can't calculate the call sequence, but I'm saying that calculating it is fundamentally wrong - it's an antipattern. If you want to be sure of the call sequence, use callbacks or promises, but not events.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question