Last active
December 24, 2018 18:58
-
-
Save rajikaimal/6480c7cb16b2adf9081f57a108c8230a to your computer and use it in GitHub Desktop.
process.nextTick behaviour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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