event loop phase
One of the six stages the Node.js event loop visits in order on every turn: timers, pending callbacks, idle/prepare, poll, check and close callbacks.
In more detail
Each phase has its own queue of callbacks, which it runs until the queue is empty or a limit is reached. Between callbacks Node.js drains the microtask queues. Idle and prepare are internal phases your code cannot schedule into.
Related terms
- event loop — The central loop of an asynchronous program that waits for events, such as timers firing or data arriving, and runs the matching callbacks.
- timers phase — The first phase of each event loop turn, which runs the callbacks of setTimeout and setInterval timers that have expired.
- poll phase — The event loop phase that asks the operating system for new I/O events, runs their callbacks, and sleeps when there is nothing to do.
- check phase — The event loop phase straight after the poll phase, which runs callbacks scheduled with setImmediate.
- close callbacks phase — The last phase of each event loop turn, which runs close handlers, such as a socket's close event after socket.destroy().
Taught in
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Poll & Check Phases: I/O Callbacks & setImmediate — Node.js Internals & Backend Services