setImmediate()
A Node.js function that runs a callback in the check phase of the current event loop turn, right after I/O has been processed.
In more detail
It is the safe way to split long or recursive work, because the event loop handles I/O and timers between immediates. process.nextTick(), by contrast, runs before the loop can move on at all.
Related terms
- check phase — The event loop phase straight after the poll phase, which runs callbacks scheduled with setImmediate.
- process.nextTick() — A Node.js function that queues a callback to run as soon as the current operation finishes, before promise callbacks and before the event loop continues.
- event loop starvation — When the event loop can never move on because code keeps scheduling more immediate work, so timers and I/O are never handled.
Taught in
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Microtask Queues: process.nextTick vs Promise Timing — Node.js Internals & Backend Services
- Poll & Check Phases: I/O Callbacks & setImmediate — Node.js Internals & Backend Services
- Writable Streams: Drain Events & highWaterMark — Node.js Internals & Backend Services