1 import type { AsyncResource
, AsyncResourceOptions
} from
'node:async_hooks'
2 import { EventEmitter
} from
'node:events'
4 declare module 'events' {
5 interface EventEmitterOptions
{
7 * Enables automatic capturing of promise rejection.
9 captureRejections
?: boolean | undefined
12 interface EventEmitterAsyncResourceOptions
13 extends AsyncResourceOptions
,
16 * The type of async event.
17 * @default new.target.name if instantiated as a child class.
23 * Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require
24 * manual async tracking. Specifically, all events emitted by instances of
25 * `EventEmitterAsyncResource` will run within its async context.
27 * The EventEmitterAsyncResource class has the same methods and takes the
28 * same options as EventEmitter and AsyncResource themselves.
29 * @throws if `options.name` is not provided when instantiated directly.
30 * @since v17.4.0, v16.14.0
32 export class EventEmitterAsyncResource
extends EventEmitter
{
33 constructor (options
: EventEmitterAsyncResourceOptions
)
35 * Call all `destroy` hooks. This should only ever be called once. An error will
36 * be thrown if it is called more than once. This **must** be manually called. If
37 * the resource is left to be collected by the GC then the `destroy` hooks will
41 /** The unique asyncId assigned to the resource. */
42 readonly asyncId
: number
43 /** The same triggerAsyncId that is passed to the AsyncResource constructor. */
44 readonly triggerAsyncId
: number
45 /** The underlying AsyncResource */
46 readonly asyncResource
: AsyncResource
& {
47 readonly eventEmitter
: EventEmitterAsyncResource