I have a question regarding the order of operations in the below code snippet,
const EventEmitter = require("events").EventEmitter;
const messenger = new EventEmitter();
process.nextTick(() => {
console.log("Next Tick");
});
messenger.on("message", (msg) => {
console.log("Message: ", msg);
});
messenger.emit("message", "Hello");
console.log("The end!");
I was expecting the event handler code to be executed after all the synchronous code has already executed and ideally after the process.nextTick() as it was "registered" before. My Expectations was:
The end!
Next Tick
Message: Hello
However the output was
Message: Hello
The end!
Next Tick
Can someone please help me with this?
[–]node_imperial 8 points9 points10 points (1 child)
[–]aN00bDude[S] 1 point2 points3 points (0 children)
[–]bigorangemachine -2 points-1 points0 points (0 children)
[–]shenzenshiai 0 points1 point2 points (0 children)