| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,16 @@ loop to remain active. If there is no other activity keeping the event loop | |||
| 63 | 63 | running, the process may exit before the `Immediate` object's callback is | |
| 64 | 64 | invoked. Calling `immediate.unref()` multiple times will have no effect. | |
| 65 | 65 | ||
| 66 | + ### `immediate[Symbol.dispose]()` | ||
| 67 | + | ||
| 68 | + <!-- YAML | ||
| 69 | + added: REPLACEME | ||
| 70 | + --> | ||
| 71 | + | ||
| 72 | + > Stability: 1 - Experimental | ||
| 73 | + | ||
| 74 | + Cancels the immediate. This is similar to calling `clearImmediate()`. | ||
| 75 | + | ||
| 66 | 76 | ## Class: `Timeout` | |
| 67 | 77 | ||
| 68 | 78 | This object is created internally and is returned from [`setTimeout()`][] and | |
@@ -157,6 +167,16 @@ across [`worker_threads`][] it must first be passed to the correct | |||
| 157 | 167 | thread. This allows enhanced compatibility with browser | |
| 158 | 168 | `setTimeout()` and `setInterval()` implementations. | |
| 159 | 169 | ||
| 170 | + ### `timeout[Symbol.dispose]()` | ||
| 171 | + | ||
| 172 | + <!-- YAML | ||
| 173 | + added: REPLACEME | ||
| 174 | + --> | ||
| 175 | + | ||
| 176 | + > Stability: 1 - Experimental | ||
| 177 | + | ||
| 178 | + Cancels the timeout. | ||
| 179 | + | ||
| 160 | 180 | ## Scheduling timers | |
| 161 | 181 | ||
| 162 | 182 | A timer in Node.js is an internal construct that calls a given function after | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -228,7 +228,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 228 | 228 | copyPrototype(original.prototype, primordials, `${name}Prototype`); | |
| 229 | 229 | }); | |
| 230 | 230 | ||
| 231 | - // Define Symbol.Dispose and Symbol.AsyncDispose | ||
| 231 | + // Define Symbol.dispose and Symbol.asyncDispose | ||
| 232 | 232 | // Until these are defined by the environment. | |
| 233 | 233 | // TODO(MoLow): Remove this polyfill once Symbol.dispose and Symbol.asyncDispose are available in V8. | |
| 234 | 234 | primordials.SymbolDispose ??= primordials.SymbolFor('nodejs.dispose'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ const { | |||
| 25 | 25 | MathTrunc, | |
| 26 | 26 | ObjectCreate, | |
| 27 | 27 | ObjectDefineProperty, | |
| 28 | + SymbolDispose, | ||
| 28 | 29 | SymbolToPrimitive, | |
| 29 | 30 | } = primordials; | |
| 30 | 31 | ||
@@ -254,6 +255,10 @@ Timeout.prototype.close = function() { | |||
| 254 | 255 | return this; | |
| 255 | 256 | }; | |
| 256 | 257 | ||
| 258 | + Timeout.prototype[SymbolDispose] = function() { | ||
| 259 | + clearTimeout(this); | ||
| 260 | + }; | ||
| 261 | + | ||
| 257 | 262 | /** | |
| 258 | 263 | * Coerces a `Timeout` to a primitive. | |
| 259 | 264 | * @returns {number} | |
@@ -337,6 +342,10 @@ function clearImmediate(immediate) { | |||
| 337 | 342 | immediateQueue.remove(immediate); | |
| 338 | 343 | } | |
| 339 | 344 | ||
| 345 | + Immediate.prototype[SymbolDispose] = function() { | ||
| 346 | + clearImmediate(this); | ||
| 347 | + }; | ||
| 348 | + | ||
| 340 | 349 | module.exports = { | |
| 341 | 350 | setTimeout, | |
| 342 | 351 | clearTimeout, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + | ||
| 5 | + const timer = setTimeout(common.mustNotCall(), 10); | ||
| 6 | + const interval = setInterval(common.mustNotCall(), 10); | ||
| 7 | + const immediate = setImmediate(common.mustNotCall()); | ||
| 8 | + | ||
| 9 | + timer[Symbol.dispose](); | ||
| 10 | + interval[Symbol.dispose](); | ||
| 11 | + immediate[Symbol.dispose](); | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + process.on('exit', () => { | ||
| 15 | + assert.strictEqual(timer._destroyed, true); | ||
| 16 | + assert.strictEqual(interval._destroyed, true); | ||
| 17 | + assert.strictEqual(immediate._destroyed, true); | ||
| 18 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments