If you've worked with JavaScript for a while, you probably already understand the event loop.
You know that this:
console . log ( 'A' ) ;
Promise . resolve ( ) . then ( ( ) => { console . log ( 'B' ) ; } ) ;
setTimeout ( ( ) => { console . log ( 'C' ) ; } , 0 ) ;
console . log ( 'D' ) ;
Enter fullscreen mode
Exit fullscreen mode
prints:
A D B C
Enter fullscreen mode
Exit fullscreen mode
You probably have a mental model something like this:
Synchronous code β Microtasks β Tasks β Microtasks β Tasks β ...
Enter fullscreen mode
Exit fullscreen mode
That's a useful model for browser JavaScript.
Then you start writing a Node.js server.
And suddenly someone shows you this:
βββββββββββββββ β timers β ββββββββ¬βββββββ β βββββββββββββββ β pending β β callbacks β ββββββββ¬βββββββ β βββββββββββββββ β poll β ββββββββ¬βββββββ β βββββββββββββββ β check β ββββββββ¬βββββββ β βββββββββββββββ β close β ββββββββ¬βββββββ β ββββββββΊ timers
Enter fullscreen mode
Exit fullscreen mode
And you're told:
"This is theβ¦