DEV Community

Discussion on: setTimeout vs setImmediate vs process.nextTick

Collapse
 
nirmalpatel59 profile image
nirmalpatel59

Not sure I am understanding your explanation of setImmediate rightly.
Consider following code. setImmediate will be executed before the timer.

const fs = require('fs');
fs.readFile('raw.githubusercontent.com/komljen/... => {
racer();
});
let racer = function() {
setTimeout(() => console.log("timeout"), 0);
setImmediate(() => console.log("immediate"));
process.nextTick(() => console.log("nextTick"));
console.log("current event loop");
}