Created
September 6, 2017 22:00
-
-
Save nate-getch/585496949b32ed3d101d529f28104b21 to your computer and use it in GitHub Desktop.
Order of execution in Event Loop of Node.js
This file contains 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 fun1(){ | |
console.log('fun1 without cllback'); | |
} | |
function fun2(callback){ | |
console.log(callback('fun2 with callback')); | |
} | |
function fun3(callback){ | |
process.nextTick(() => console.log(callback('fun3 with callback + next tick'))); | |
} | |
console.log('1 '); | |
process.nextTick(() => console.error('1next tick') ); | |
setImmediate( () => console.log('immidate time out') ); | |
setTimeout( () => console.log('time out with 0') ,0); | |
setTimeout( () => console.log('time out with 500') ,500); | |
process.nextTick(() => console.error('2next tick') ); | |
fun1(); | |
fun2( (r) => r ); | |
fun3( (r) => r ); | |
console.log('3'); | |
//out put | |
/* | |
1 | |
fun1 without cllback | |
fun2 with callback | |
3 | |
1next tick | |
2next tick | |
fun3 with callback + next tick | |
time out with 0 | |
immidate time out | |
time out with 500 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment