Skip to content

Instantly share code, notes, and snippets.

@rajikaimal
Last active December 24, 2018 18:58
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/6480c7cb16b2adf9081f57a108c8230a to your computer and use it in GitHub Desktop.
Save rajikaimal/6480c7cb16b2adf9081f57a108c8230a to your computer and use it in GitHub Desktop.
process.nextTick behaviour
function iter(num) {
if(num > 5) return;
setImmediate(() => {
console.log('SetImmediate');
});
process.nextTick(() => {
console.log(`NextTick, iteration ${num}`);
iter(num + 1);
});
}
iter(0);
// NextTick, iteration 0
// NextTick, iteration 1
// NextTick, iteration 2
// NextTick, iteration 3
// NextTick, iteration 4
// NextTick, iteration 5
// SetImmediate
// SetImmediate
// SetImmediate
// SetImmediate
// SetImmediate
// SetImmediate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment