test: use sinon stub to simplify code
[poolifier.git] / @types / events.d.ts
CommitLineData
b5604034
JB
1import type { AsyncResource, AsyncResourceOptions } from 'node:async_hooks'
2import { EventEmitter } from 'node:events'
3
cd312fe9 4declare module 'events' {
b5604034
JB
5 interface EventEmitterOptions {
6 /**
7 * Enables automatic capturing of promise rejection.
8 */
9 captureRejections?: boolean | undefined
10 }
11
12 interface EventEmitterAsyncResourceOptions
13 extends AsyncResourceOptions,
14 EventEmitterOptions {
15 /**
16 * The type of async event.
d8531d89 17 * @default new.target.name if instantiated as a child class.
b5604034
JB
18 */
19 name?: string
20 }
21
22 /**
95361230 23 * Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that require
b5604034
JB
24 * manual async tracking. Specifically, all events emitted by instances of
25 * `EventEmitterAsyncResource` will run within its async context.
26 *
27 * The EventEmitterAsyncResource class has the same methods and takes the
28 * same options as EventEmitter and AsyncResource themselves.
9ef45721
JB
29 * @throws if `options.name` is not provided when instantiated directly.
30 * @since v17.4.0, v16.14.0
b5604034
JB
31 */
32 export class EventEmitterAsyncResource extends EventEmitter {
6e4915f8
JB
33 /**
34 * @param options Only optional in child class.
35 */
36 constructor (options?: EventEmitterAsyncResourceOptions)
b5604034
JB
37 /**
38 * Call all `destroy` hooks. This should only ever be called once. An error will
39 * be thrown if it is called more than once. This **must** be manually called. If
40 * the resource is left to be collected by the GC then the `destroy` hooks will
41 * never be called.
b5604034 42 */
9ef45721 43 emitDestroy (): void
b5604034 44 /** The unique asyncId assigned to the resource. */
85126db3 45 readonly asyncId: number
b5604034 46 /** The same triggerAsyncId that is passed to the AsyncResource constructor. */
85126db3 47 readonly triggerAsyncId: number
b5604034 48 /** The underlying AsyncResource */
85126db3 49 readonly asyncResource: AsyncResource & {
b5604034
JB
50 readonly eventEmitter: EventEmitterAsyncResource
51 }
52 }
53}