Skip to content

Commit 62a66aa

Browse files
docs: update explanation of setImmediate vs setTimeout (#8623)
* docs: update explanation of setImmediate vs setTimeout Clarifies the execution order of setTimeout and setImmediate when called from the main module and inside an I/O callback. Signed-off-by: Sébastien Dan <sebastien.dan@ikmail.com> * fix: use bold and lowercase format for event loop phases Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sébastien Dan <sdan@polygon.technology> --------- Signed-off-by: Sébastien Dan <sebastien.dan@ikmail.com> Signed-off-by: Sébastien Dan <sdan@polygon.technology> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c9fa123 commit 62a66aa

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

apps/site/pages/en/learn/asynchronous-work/understanding-setimmediate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ How is `setImmediate()` different from `setTimeout(() => {}, 0)` (passing a 0ms
2020

2121
A function passed to `process.nextTick()` is going to be executed on the current iteration of the event loop, after the current operation ends. This means it will always execute before `setTimeout` and `setImmediate`.
2222

23-
A `setTimeout()` callback with a 0ms delay is very similar to `setImmediate()`. The execution order will depend on various factors, but they will be both run in the next iteration of the event loop.
23+
A `setTimeout()` callback with a 0ms delay is very similar to `setImmediate()`. The execution order will depend on various factors, but they will be both run in the next iteration (the first one) of the event loop when called from the main module. When scheduled inside an I/O callback, setImmediate is guaranteed to run in the current iteration's **check** phase, while setTimeout must wait for the **timers** phase of the subsequent iteration.
2424

2525
A `process.nextTick` callback is added to `process.nextTick queue`. A `Promise.then()` callback is added to `promises microtask queue`. A `setTimeout`, `setImmediate` callback is added to `macrotask queue`.
2626

0 commit comments

Comments
 (0)