Skip to content

Instantly share code, notes, and snippets.

@rajikaimal
Last active December 24, 2018 18:57
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/ec8ca90fd891bf4f05aa83c218cf755b to your computer and use it in GitHub Desktop.
Save rajikaimal/ec8ca90fd891bf4f05aa83c218cf755b to your computer and use it in GitHub Desktop.
setTimeout vs setImmediate within an I/O cycle
const fs = require("fs");
fs.readFile(__filename, () => {
setTimeout(() => {
console.log('SetTimeout callback');
}, 0);
setImmediate(() => {
console.log('SetImmediate callback');
});
});
// Output:
// SetImmediate callback
// SetTimeout callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment