The class AsyncResource was designed to be extended by the embedder's async resources. Using this users can easily trigger the lifetime events of their own resources.

### Hierarchy

- AsyncResource
  - PerformanceObserver

## Index

### Constructors

- constructor

### Methods

- asyncId
- emitAfter
- emitBefore
- emitDestroy
- runInAsyncScope
- triggerAsyncId

## Constructors

### constructor

- new AsyncResource(type: string, triggerAsyncId?: number | AsyncResourceOptions): AsyncResource

- - Defined in node_modules/@types/node/async_hooks.d.ts:92

  AsyncResource() is meant to be extended. Instantiating a new AsyncResource() also triggers init. If triggerAsyncId is omitted then async_hook.executionAsyncId() is used.

  #### Parameters

  - ##### type: string

    The type of async event.

  - ##### Optional triggerAsyncId: number | AsyncResourceOptions

    The ID of the execution context that created this async event (default: `executionAsyncId()`), or an AsyncResourceOptions object (since 9.3)

  #### Returns AsyncResource

## Methods

### asyncId

- asyncId(): number

- - Defined in node_modules/@types/node/async_hooks.d.ts:137

  #### Returns number

  the unique ID assigned to this AsyncResource instance.

### emitAfter

- emitAfter(): void

- - Defined in node_modules/@types/node/async_hooks.d.ts:114

  Call AsyncHooks after callbacks.

  deprecated

    since 9.6 - Use asyncResource.runInAsyncScope() instead.

  #### Returns void

### emitBefore

- emitBefore(): void

- - Defined in node_modules/@types/node/async_hooks.d.ts:108

  Call AsyncHooks before callbacks.

  deprecated

    since 9.6 - Use asyncResource.runInAsyncScope() instead.

  #### Returns void

### emitDestroy

- emitDestroy(): void

- - Defined in node_modules/@types/node/async_hooks.d.ts:132

  Call AsyncHooks destroy callbacks.

  #### Returns void

### runInAsyncScope

- runInAsyncScope<This, Result>(fn: function, thisArg?: This, ...args: any[]): Result

- - Defined in node_modules/@types/node/async_hooks.d.ts:127

  Call the provided function with the provided arguments in the execution context of the async resource. This will establish the context, trigger the AsyncHooks before callbacks, call the function, trigger the AsyncHooks after callbacks, and then restore the original execution context.

  #### Type parameters

  - #### This

  - #### Result

  #### Parameters

  - ##### fn: function

    The function to call in the execution context of this async resource.

    - - (this: This, ...args: any[]): Result

      - #### Parameters

        - ##### this: This

        - ##### Rest ...args: any[]

        #### Returns Result

  - ##### Optional thisArg: This

    The receiver to be used for the function call.

  - ##### Rest ...args: any[]

    Optional arguments to pass to the function.

  #### Returns Result

### triggerAsyncId

- triggerAsyncId(): number

- - Defined in node_modules/@types/node/async_hooks.d.ts:142

  #### Returns number

  the trigger ID for this AsyncResource instance.

Generated using TypeDoc