1. Timers phase
The timers phase runs callbacks scheduled by setTimeout and setInterval whose threshold has elapsed.
// 1. timers -> setTimeout / setInterval callbacksTyporithm · hard
Step 1 of 8 · intro card
Event Loop
libuv's event loop cycles through fixed phases in order: timers, pending callbacks, poll, check, then close callbacks. The poll phase is where the loop waits for I/O. Each phase fully drains its own callback queue before moving on, and non-blocking I/O is what lets one thread stay concurrent.
Node's event loop, implemented by libuv, repeats a fixed sequence of phases: timers, pending callbacks, poll, check, and finally close callbacks, then loops back to the start.
The poll phase is the heart of the loop — it is where Node waits for and retrieves incoming I/O events and runs their callbacks, blocking there until work arrives or a timer is due.
Each phase has its own callback queue and fully drains every ready callback in it before advancing to the next phase; because I/O is non-blocking, a single thread can juggle many connections concurrently.
Order: timers -> pending callbacks -> poll -> check -> close callbacks.
The poll phase waits for I/O and runs its callbacks.
Each phase drains its own queue before the next runs.
// libuv runs these phases in a fixed order, looping forever
// 1. timers -> setTimeout / setInterval callbacks
// 2. pending callbacks-> deferred system (TCP error) callbacks
// 3. poll -> wait for I/O, run its callbacks
// 4. check -> setImmediate callbacks
// 5. close callbacks -> 'close' events, e.g. socket.on('close')
// each phase fully drains its own callback queue before moving onConnect each part of the code to the concept before you type.
The timers phase runs callbacks scheduled by setTimeout and setInterval whose threshold has elapsed.
// 1. timers -> setTimeout / setInterval callbacksThe poll phase is where the loop waits for and processes I/O events; it can block here until work or a timer is due.
// 3. poll -> wait for I/O, run its callbacksThe check phase runs setImmediate callbacks, which is the phase immediately after poll.
// 4. check -> setImmediate callbacksThe close callbacks phase fires 'close' events like socket.on('close') before the loop wraps around.
// 5. close callbacks -> 'close' events, e.g. socket.on('close')Each phase has its own FIFO queue and runs every ready callback in it before advancing to the next phase.
// each phase fully drains its own callback queue before moving onRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.