Skip to content

Commit 13422f2

Browse files
committed
doc: add before/after snippets for DEP0208
Add code examples showing migration from Timeout.prototype[Symbol.dispose] to clearTimeout(). Refs: #64615 Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent c6558b0 commit 13422f2

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎doc/api/deprecations.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,6 +4663,31 @@ implement `Symbol.dispose`. Prefer [`clearTimeout()`][] instead to cancel a
46634663
timeout. This deprecation does not apply to [`Immediate`][] objects returned by
46644664
[`setImmediate()`][].
46654665
4666+
```cjs
4667+
// Deprecated
4668+
const timeout = setTimeout(() => {}, 1000);
4669+
timeout[Symbol.dispose]();
4670+
4671+
{
4672+
using t = setTimeout(() => {}, 1000);
4673+
} // Calls timeout[Symbol.dispose]()
4674+
```
4675+
4676+
```cjs
4677+
// Use this instead
4678+
const timeout = setTimeout(() => {}, 1000);
4679+
clearTimeout(timeout);
4680+
4681+
{
4682+
const t = setTimeout(() => {}, 1000);
4683+
try {
4684+
// ...
4685+
} finally {
4686+
clearTimeout(t);
4687+
}
4688+
}
4689+
```
4690+
46664691
[DEP0142]: #dep0142-repl_builtinlibs
46674692
[DEP0156]: #dep0156-aborted-property-and-abort-aborted-event-in-http
46684693
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf

0 commit comments

Comments
 (0)