MΓ³dulo 02 Β· The Event Loop & Async β LecciΓ³n 2 de 3 Β· ~11 min
Inside the event loop
Macrotasks, microtasks, and phases
The event loop runs in phases, each with its own queue of callbacks. You don't need all six for interviews, but you need three plus one rule:
- Timers β runs
setTimeout/setIntervalcallbacks whose time is up. - Poll (I/O) β retrieves and runs I/O callbacks (a DB reply, an incoming request). This is where most of your code runs.
- Check β runs
setImmediatecallbacks, right after poll.
These queued callbacks are called macrotasks, and Node runs one per tick of a phase.