Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,18 @@ const server = net.createServer((conn) => {
Promise contexts may not get valid `triggerAsyncId`s by default. See
the section on [promise execution tracking][].

### `async_hooks.asyncWrapProviders`

<!-- YAML
added: REPLACEME
-->

* Returns: A map of provider types to the corresponding numeric id.
This map contains all the event types that might be emitted by the `async_hooks.init()` event.

This feature suppresses the deprecated usage of `process.binding('async_wrap').Providers`.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a link to DEP0111

See: [DEP0111][]

## Promise execution tracking

By default, promise executions are not assigned `asyncId`s due to the relatively
Expand Down Expand Up @@ -841,6 +853,7 @@ The documentation for this class has moved [`AsyncResource`][].

The documentation for this class has moved [`AsyncLocalStorage`][].

[DEP0111]: deprecations.md#dep0111-processbinding
[Hook Callbacks]: #hook-callbacks
[PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk/edit
[`AsyncLocalStorage`]: async_context.md#class-asynclocalstorage
Expand Down
3 changes: 3 additions & 0 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
ObjectIs,
ReflectApply,
Symbol,
ObjectFreeze,
} = primordials;

const {
Expand All @@ -29,6 +30,7 @@ const internal_async_hooks = require('internal/async_hooks');
// resource gets gced.
const { registerDestroyHook } = internal_async_hooks;
const {
asyncWrap,
executionAsyncId,
triggerAsyncId,
// Private API
Expand Down Expand Up @@ -352,6 +354,7 @@ module.exports = {
executionAsyncId,
triggerAsyncId,
executionAsyncResource,
asyncWrapProviders: ObjectFreeze({ __proto__: null, ...asyncWrap.Providers }),
// Embedder API
AsyncResource,
};
3 changes: 3 additions & 0 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,8 @@ module.exports = {
after: emitAfterNative,
destroy: emitDestroyNative,
promise_resolve: emitPromiseResolveNative
},
asyncWrap: {
Providers: async_wrap.Providers,
}
};
18 changes: 18 additions & 0 deletions test/async-hooks/test-async-wrap-providers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const { internalBinding } = require('internal/test/binding');
const providers = internalBinding('async_wrap').Providers;
const assert = require('assert');
const { asyncWrapProviders } = require('async_hooks');

assert.ok(typeof asyncWrapProviders === 'object');
assert.deepStrictEqual(asyncWrapProviders, { __proto__: null, ...providers });

const providerKeys = Object.keys(asyncWrapProviders);
assert.throws(() => {
asyncWrapProviders[providerKeys[0]] = 'another value';
}, common.expectsError({
name: 'TypeError',
}), 'should not allow modify asyncWrap providers');