| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 415b42f commit 0691649
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -758,6 +758,18 @@ const server = net.createServer((conn) => { | |||
| 758 | 758 | Promise contexts may not get valid `triggerAsyncId`s by default. See | |
| 759 | 759 | the section on [promise execution tracking][]. | |
| 760 | 760 | ||
| 761 | + ### `async_hooks.asyncWrapProviders` | ||
| 762 | + | ||
| 763 | + <!-- YAML | ||
| 764 | + added: REPLACEME | ||
| 765 | + --> | ||
| 766 | + | ||
| 767 | + * Returns: A map of provider types to the corresponding numeric id. | ||
| 768 | + This map contains all the event types that might be emitted by the `async_hooks.init()` event. | ||
| 769 | + | ||
| 770 | + This feature suppresses the deprecated usage of `process.binding('async_wrap').Providers`. | ||
| 771 | + See: [DEP0111][] | ||
| 772 | + | ||
| 761 | 773 | ## Promise execution tracking | |
| 762 | 774 | ||
| 763 | 775 | By default, promise executions are not assigned `asyncId`s due to the relatively | |
@@ -841,6 +853,7 @@ The documentation for this class has moved [`AsyncResource`][]. | |||
| 841 | 853 | ||
| 842 | 854 | The documentation for this class has moved [`AsyncLocalStorage`][]. | |
| 843 | 855 | ||
| 856 | + [DEP0111]: deprecations.md#dep0111-processbinding | ||
| 844 | 857 | [Hook Callbacks]: #hook-callbacks | |
| 845 | 858 | [PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk/edit | |
| 846 | 859 | [`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ const { | |||
| 11 | 11 | ObjectIs, | |
| 12 | 12 | ReflectApply, | |
| 13 | 13 | Symbol, | |
| 14 | + ObjectFreeze, | ||
| 14 | 15 | } = primordials; | |
| 15 | 16 | ||
| 16 | 17 | const { | |
@@ -29,6 +30,7 @@ const internal_async_hooks = require('internal/async_hooks'); | |||
| 29 | 30 | // resource gets gced. | |
| 30 | 31 | const { registerDestroyHook } = internal_async_hooks; | |
| 31 | 32 | const { | |
| 33 | + asyncWrap, | ||
| 32 | 34 | executionAsyncId, | |
| 33 | 35 | triggerAsyncId, | |
| 34 | 36 | // Private API | |
@@ -352,6 +354,7 @@ module.exports = { | |||
| 352 | 354 | executionAsyncId, | |
| 353 | 355 | triggerAsyncId, | |
| 354 | 356 | executionAsyncResource, | |
| 357 | + asyncWrapProviders: ObjectFreeze({ __proto__: null, ...asyncWrap.Providers }), | ||
| 355 | 358 | // Embedder API | |
| 356 | 359 | AsyncResource, | |
| 357 | 360 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -612,5 +612,8 @@ module.exports = { | |||
| 612 | 612 | after: emitAfterNative, | |
| 613 | 613 | destroy: emitDestroyNative, | |
| 614 | 614 | promise_resolve: emitPromiseResolveNative | |
| 615 | + }, | ||
| 616 | + asyncWrap: { | ||
| 617 | + Providers: async_wrap.Providers, | ||
| 615 | 618 | } | |
| 616 | 619 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const { internalBinding } = require('internal/test/binding'); | ||
| 6 | + const providers = internalBinding('async_wrap').Providers; | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const { asyncWrapProviders } = require('async_hooks'); | ||
| 9 | + | ||
| 10 | + assert.ok(typeof asyncWrapProviders === 'object'); | ||
| 11 | + assert.deepStrictEqual(asyncWrapProviders, { __proto__: null, ...providers }); | ||
| 12 | + | ||
| 13 | + const providerKeys = Object.keys(asyncWrapProviders); | ||
| 14 | + assert.throws(() => { | ||
| 15 | + asyncWrapProviders[providerKeys[0]] = 'another value'; | ||
| 16 | + }, common.expectsError({ | ||
| 17 | + name: 'TypeError', | ||
| 18 | + }), 'should not allow modify asyncWrap providers'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments