Day 2 - The Event Loop's Route: Six Phases and Cleanup Order
📇 Concept Card: Six Phases of the Event Loop
Node.js event loop visits 6 stations in this order: timers → pending → idle/prepare → poll → check → close. Most action happens at poll (waiting for I/O). nextTick and microtask are side windows that clear between phases.
poll Station: The Heart of the Loop
This is where the waiter (event loop) waits for network/file I/O callbacks. If nothing is waiting, it spins here. Everything backs up if poll gets blocked.
✂️ Two Side Windows: nextTick and Microtask
After each phase (except poll), Node clears the microtask queue (Promise.then, async/await). Then nextTick. They are NOT part of the loop phases; they clear between.
If you recursively call process.nextTick, you can starve the loop. Use setImmediate to yield.