cac
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitterReferencingAsyncResource

Index

Constructors

constructor

  • 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 v9.3.0)

    Returns EventEmitterReferencingAsyncResource

Properties

Readonly eventEmitter

Methods

asyncId

  • asyncId(): number
  • Returns number

    The unique asyncId assigned to the resource.

bind

  • bind<Func>(fn: Func): Func
  • Binds the given function to execute to this AsyncResource's scope.

    since

    v14.8.0, v12.19.0

    Type parameters

    • Func: (...args: any[]) => any

    Parameters

    • fn: Func

      The function to bind to the current AsyncResource.

    Returns Func

emitDestroy

  • emitDestroy(): this
  • Call all destroy hooks. This should only ever be called once. An error will be thrown if it is called more than once. This must be manually called. If the resource is left to be collected by the GC then the destroy hooks will never be called.

    Returns this

    A reference to asyncResource.

runInAsyncScope

  • runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result
  • 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.

    since

    v9.6.0

    Type parameters

    • This

    • Result

    Parameters

    • fn: (this: This, ...args: any[]) => Result

      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
  • Returns number

    The same triggerAsyncId that is passed to the AsyncResource constructor.

Static bind

  • bind<Func, ThisArg>(fn: Func, type?: undefined | string, thisArg?: ThisArg): Func
  • Binds the given function to the current execution context.

    since

    v14.8.0, v12.19.0

    Type parameters

    • Func: (this: ThisArg, ...args: any[]) => any

    • ThisArg

    Parameters

    • fn: Func

      The function to bind to the current execution context.

    • Optional type: undefined | string

      An optional name to associate with the underlying AsyncResource.

    • Optional thisArg: ThisArg

    Returns Func

Legend

  • Variable
  • Function
  • Type alias
  • Interface
  • Property
  • Class

Generated using TypeDoc