| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d35333a commit 3f69b18
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3227,11 +3227,13 @@ console.log(`The parent process is pid ${ppid}`); | |||
| 3227 | 3227 | added: REPLACEME | |
| 3228 | 3228 | --> | |
| 3229 | 3229 | ||
| 3230 | + > Stability: 1 - Experimental | ||
| 3231 | + | ||
| 3230 | 3232 | * `maybeRefable` {any} An object that may be "refable". | |
| 3231 | 3233 | ||
| 3232 | 3234 | An object is "refable" if it implements the Node.js "Refable protocol". | |
| 3233 | - Specifically, this means that the object implements the `Symbol.for('node:ref')` | ||
| 3234 | - and `Symbol.for('node:unref')` methods. "Ref'd" objects will keep the Node.js | ||
| 3235 | + Specifically, this means that the object implements the `Symbol.for('nodejs.ref')` | ||
| 3236 | + and `Symbol.for('nodejs.unref')` methods. "Ref'd" objects will keep the Node.js | ||
| 3235 | 3237 | event loop alive, while "unref'd" objects will not. Historically, this was | |
| 3236 | 3238 | implemented by using `ref()` and `unref()` methods directly on the objects. | |
| 3237 | 3239 | This pattern, however, is being deprecated in favor of the "Refable protocol" | |
@@ -4284,11 +4286,13 @@ In [`Worker`][] threads, `process.umask(mask)` will throw an exception. | |||
| 4284 | 4286 | added: REPLACEME | |
| 4285 | 4287 | --> | |
| 4286 | 4288 | ||
| 4289 | + > Stability: 1 - Experimental | ||
| 4290 | + | ||
| 4287 | 4291 | * `maybeUnfefable` {any} An object that may be "unref'd". | |
| 4288 | 4292 | ||
| 4289 | 4293 | An object is "unrefable" if it implements the Node.js "Refable protocol". | |
| 4290 | - Specifically, this means that the object implements the `Symbol.for('node:ref')` | ||
| 4291 | - and `Symbol.for('node:unref')` methods. "Ref'd" objects will keep the Node.js | ||
| 4294 | + Specifically, this means that the object implements the `Symbol.for('nodejs.ref')` | ||
| 4295 | + and `Symbol.for('nodejs.unref')` methods. "Ref'd" objects will keep the Node.js | ||
| 4292 | 4296 | event loop alive, while "unref'd" objects will not. Historically, this was | |
| 4293 | 4297 | implemented by using `ref()` and `unref()` methods directly on the objects. | |
| 4294 | 4298 | This pattern, however, is being deprecated in favor of the "Refable protocol" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -425,12 +425,14 @@ function toggleTraceCategoryState(asyncHooksEnabled) { | |||
| 425 | 425 | const { arch, platform, version } = process; | |
| 426 | 426 | ||
| 427 | 427 | function ref(maybeRefable) { | |
| 428 | - const fn = maybeRefable?.[SymbolFor('node:ref')] || maybeRefable?.ref; | ||
| 428 | + const fn = maybeRefable?.[SymbolFor('nodejs.ref')] || maybeRefable?.[SymbolFor('node:ref')] || maybeRefable?.ref; | ||
| 429 | 429 | if (typeof fn === 'function') FunctionPrototypeCall(fn, maybeRefable); | |
| 430 | 430 | } | |
| 431 | 431 | ||
| 432 | 432 | function unref(maybeRefable) { | |
| 433 | - const fn = maybeRefable?.[SymbolFor('node:unref')] || maybeRefable?.unref; | ||
| 433 | + const fn = maybeRefable?.[SymbolFor('nodejs.unref')] || | ||
| 434 | + maybeRefable?.[SymbolFor('node:unref')] || | ||
| 435 | + maybeRefable?.unref; | ||
| 434 | 436 | if (typeof fn === 'function') FunctionPrototypeCall(fn, maybeRefable); | |
| 435 | 437 | } | |
| 436 | 438 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,18 @@ class Foo { | |||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | class Foo2 { | |
| 26 | + refCalled = 0; | ||
| 27 | + unrefCalled = 0; | ||
| 28 | + [Symbol.for('nodejs.ref')]() { | ||
| 29 | + this.refCalled++; | ||
| 30 | + } | ||
| 31 | + [Symbol.for('nodejs.unref')]() { | ||
| 32 | + this.unrefCalled++; | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + // TODO(aduh95): remove support for undocumented symbol | ||
| 37 | + class Foo3 { | ||
| 26 | 38 | refCalled = 0; | |
| 27 | 39 | unrefCalled = 0; | |
| 28 | 40 | [Symbol.for('node:ref')]() { | |
@@ -39,14 +51,19 @@ describe('process.ref/unref work as expected', () => { | |||
| 39 | 51 | // just work. | |
| 40 | 52 | const foo1 = new Foo(); | |
| 41 | 53 | const foo2 = new Foo2(); | |
| 54 | + const foo3 = new Foo3(); | ||
| 42 | 55 | process.ref(foo1); | |
| 43 | 56 | process.unref(foo1); | |
| 44 | 57 | process.ref(foo2); | |
| 45 | 58 | process.unref(foo2); | |
| 59 | + process.ref(foo3); | ||
| 60 | + process.unref(foo3); | ||
| 46 | 61 | strictEqual(foo1.refCalled, 1); | |
| 47 | 62 | strictEqual(foo1.unrefCalled, 1); | |
| 48 | 63 | strictEqual(foo2.refCalled, 1); | |
| 49 | 64 | strictEqual(foo2.unrefCalled, 1); | |
| 65 | + strictEqual(foo3.refCalled, 1); | ||
| 66 | + strictEqual(foo3.unrefCalled, 1); | ||
| 50 | 67 | ||
| 51 | 68 | // Objects that implement the legacy API also just work. | |
| 52 | 69 | const i = setInterval(() => {}, 1000); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments