Skip to content

timers: runtime-deprecate Timeout.prototype[Symbol.dispose]#64615

Open
mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:fix/dep0208-timeout-symbol-dispose
Open

timers: runtime-deprecate Timeout.prototype[Symbol.dispose]#64615
mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:fix/dep0208-timeout-symbol-dispose

Conversation

@mcollina

Copy link
Copy Markdown
Member

Emit a DEP0208 runtime deprecation warning when
Timeout.prototype[Symbol.dispose] is called.

The web platform setTimeout() / setInterval() APIs return a number,
which cannot implement Symbol.dispose. Leaving this integration in place
encourages code that is incompatible between Node.js and browsers (and
other server-side platforms that follow the web timers API).

Immediate.prototype[Symbol.dispose] is intentionally left unchanged,
since setImmediate is not a web platform API.

Prefer clearTimeout() to cancel a timeout.

Fixes: #58689

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/userland-migrations

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Jul 20, 2026
@mcollina
mcollina force-pushed the fix/dep0208-timeout-symbol-dispose branch from f139ee5 to 669757d Compare July 20, 2026 08:27
Emit a DEP0208 deprecation warning when
Timeout.prototype[Symbol.dispose] is called. The web platform
setTimeout()/setInterval() APIs return a number, which cannot
implement Symbol.dispose. Prefer clearTimeout() instead.
Immediate.prototype[Symbol.dispose] is left unchanged.

Fixes: nodejs#58689
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the fix/dep0208-timeout-symbol-dispose branch from 669757d to c6558b0 Compare July 20, 2026 08:49
Comment thread doc/api/deprecations.md
[`setTimeout()`][] and [`setInterval()`][] APIs return a number, which cannot
implement `Symbol.dispose`. Prefer [`clearTimeout()`][] instead to cancel a
timeout. This deprecation does not apply to [`Immediate`][] objects returned by
[`setImmediate()`][].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this deprecation have clear before after change could you add code snippets to that.

Add code examples showing migration from
Timeout.prototype[Symbol.dispose] to clearTimeout().

Refs: nodejs#64615
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina

Copy link
Copy Markdown
Member Author

Added before/after code snippets to DEP0208 as requested.

@Renegade334

Copy link
Copy Markdown
Member

Immediate.prototype[Symbol.dispose] is intentionally left unchanged,
since setImmediate is not a web platform API.

Web or not, I'd add a +1 for deprecating this as well for consistency, are there any real uses for disposing of an Immediate in the same block as it was created?

https://github.com/search?q=language%3AJavaScript+%2Fusing+%5CS%2B+%3D+setImmediate%2F&type=code

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.14%. Comparing base (fb5d01f) to head (13422f2).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64615      +/-   ##
==========================================
- Coverage   90.24%   90.14%   -0.11%     
==========================================
  Files         739      741       +2     
  Lines      241772   242077     +305     
  Branches    45561    45541      -20     
==========================================
+ Hits       218194   218211      +17     
- Misses      15111    15362     +251     
- Partials     8467     8504      +37     
Files with missing lines Coverage Δ
lib/timers.js 100.00% <100.00%> (ø)

... and 59 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in term of docs it's super nice.

and in terms of the deprecation LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Symbol.dispose integration in setTimeout and setInterval

5 participants