docs: update explanation of setImmediate vs setTimeout#8623
docs: update explanation of setImmediate vs setTimeout#8623sebastiendan wants to merge 2 commits intonodejs:mainfrom
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
👋 Codeowner Review RequestThe following codeowners have been identified for the changed files: Team reviewers: @nodejs/nodejs-website Please review the changes when you have a chance. Thank you! 🙏 |
There was a problem hiding this comment.
Pull request overview
This PR updates the documentation for setImmediate() to clarify the execution order differences between setTimeout() and setImmediate() in different contexts (main module vs I/O callbacks). The change addresses a confusing statement about when these functions execute in the event loop.
Changes:
- Clarified that when called from the main module, both
setTimeout(0)andsetImmediate()run in the next iteration of the event loop - Added explanation that when scheduled inside an I/O callback,
setImmediateexecutes in the current iteration's check phase whilesetTimeoutmust wait for the subsequent iteration's timers phase
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
apps/site/pages/en/learn/asynchronous-work/understanding-setimmediate.md
Outdated
Show resolved
Hide resolved
apps/site/pages/en/learn/asynchronous-work/understanding-setimmediate.md
Outdated
Show resolved
Hide resolved
apps/site/pages/en/learn/asynchronous-work/understanding-setimmediate.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Sébastien Dan <sdan@polygon.technology>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
cc @nodejs/timers |
Description
Clarifies the execution order of setTimeout and setImmediate when called from the main module and inside an I/O callback.
The current
they will be both run in the next iteration of the event loopphrasing is confusing without the explicit context of where the code is run (main module vs I/O callback).Check List
pnpm formatto ensure the code follows the style guide.pnpm testto check if all tests are passing.pnpm buildto check if the website builds without errors.