Skip to content

Instantly share code, notes, and snippets.

@rajikaimal
Last active December 24, 2018 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajikaimal/f4a8c4f6ea6e154aea3bddc125d4156e to your computer and use it in GitHub Desktop.
Save rajikaimal/f4a8c4f6ea6e154aea3bddc125d4156e to your computer and use it in GitHub Desktop.
setImmediate vs setTimeout vs process.nextTick
const fs = require('fs');
fs.readFile(__filename, () => {
setTimeout(() => {
console.log('SetTimeout callback');
}, 0);
setImmediate(() => {
console.log('SetImmediate callback');
});
process.nextTick(() => {
console.log('NextTick');
});
});
// Output:
// NextTick
// SetImmediate callback
// SetTimeout callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment