DEV Community

Discussion on: setTimeout vs setImmediate vs process.nextTick

Collapse
jaishwalrishabh profile image
Rishabh jaishwal

code 1

setTimeout(function cb1() {
console.log("getting")
}, 0);

setImmediate(cb1);

code 2

setImmediate(cb1);
setTimeout(function cb1() {
console.log("getting")
}, 0);


code 3

function cb1() {
console.log("call second");
}
setImmediate(cb1);
setTimeout(function cb1() {
console.log("getting")
}, 0);
process.nextTick(cb);


code 3

function cb1() {
console.log("call second");
}

setTimeout(function cb1() {
console.log("getting")
}, 0);
setImmediate(cb1);
process.nextTick(cb);


SEE UNEXPECTED BEHAVIOUR