timers phase
The first phase of each event loop turn, which runs the callbacks of setTimeout and setInterval timers that have expired.
In more detail
libuv keeps timers in a min-heap ordered by expiry time, so it only needs to look at the earliest one to know whether any are due. A timer's callback therefore never runs before its delay, but it can run later when earlier phases are busy.
Related terms
- 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.
- setTimeout — A JavaScript function that runs a callback once after at least the given number of milliseconds, unless clearTimeout cancels it first.
- min-heap — A heap in which every parent is less than or equal to its children, so the minimum is at the root; a max-heap reverses the order.
Taught in
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Timers Phase: setTimeout, Min-Heap Scheduling & Drift — Node.js Internals & Backend Services