The Node.js Event Loop: libuv Phases, Timers & nextTick
Step through the server-side event loop, the one libuv runs — not the browser model. Walk the phase cycle (timers, pending callbacks, poll, check, close), then settle the classics: setImmediate vs setTimeout(0) vs process.nextTick, and exactly where microtasks drain between phases. Every ordering puzzle here was executed and verified on Node.js. Explanation-first feedback reveals the why after each answer.
Questions
- Not answered. Which component actually owns and runs the event loop in Node.js?
- Not answered. Each turn of the loop runs its user-observable phases in which order?
- Not answered. Which of these callbacks are executed during the timers phase?
- Not answered. What makes the poll phase different from every other phase?
- Not answered.
setImmediate(fn)callbacks execute in which event-loop phase? (one word) - Not answered. A TCP socket emits its
'close'event. Which phase fires that handler? - Not answered. Where does
process.nextTicksit in the libuv phase model? - Not answered. In what order do these four lines log?
- Not answered. Between two phases, Node runs a "microtask checkpoint." Which callbacks drain there?
- Not answered. Inside a file-read callback, when does the code after
awaitrun? - Not answered. Why can a recursive
process.nextTickfreeze an entire Node server? - Not answered. At the top level of a module, what is the output order here?
- Not answered. Move the very same two calls inside an I/O callback. Now what?
- Not answered. You schedule
setTimeout(fn, 10), then run a 60 ms synchronous loop. When doesfnfire? - Not answered. Node clamps any
setTimeoutdelay below 1 up to a floor. SosetTimeout(fn, 0)is treated as how many milliseconds? (number only) - Not answered. A server warms up: it reads a config file, then schedules four things. What order logs?
- Not answered. This snippet proves microtasks drain between every phase. What is the order?
- Not answered. You must process a huge job in chunks without freezing incoming requests. Which call yields control between chunks?