I read this on the node documentation :
setImmediate(callback, [arg], [...])
To schedule the "immediate" execution of callback after I/O events callbacks and before
setTimeout
andsetInterval
However, I see the opposite.
setTimeout
is executed before setImmediate
.
Does someone have an explenation for this behavior, or any documentation on the node event loop ?
Thanks :)
code :
var index = 0;
function test(name) {
console.log((index++) + " " + name);
}
setImmediate(function() {
test("setImmediate");
})
setTimeout(function() {
test("setTimeout");
}, 0);
process.nextTick(function() {
test("nextTick");
})
test("directCall");
output :
0 directCall
1 nextTick
2 setTimeout
3 setImmediate