1
Timers
setTimeout setInterval
2
Pending Callbacks
deferred I/O errors from previous iteration
TCP errors
3
Idle, Prepare
internal to Node
4
Poll
the workhorse
where most of your async code actually executes
1 First — drain the poll queue:
fs.readFile http request socket data dns.lookup
then, if the queue is empty — in order:
2 if setImmediate is pending → jump to Check
3 else if a timer expired → next iteration Timers
4 else → block here and wait for new I/O
5
Check
runs right after Poll
setImmediate
6
Close Callbacks
socket.on('close'), server.close()
close
I/O →
incoming: connections, data, etc.
↻ next tick
once all six phases drain, the loop starts over