Options
All
  • Public
  • Public/Protected
  • All
Menu

When having multiple instances of AsyncLocalStorage, they are independent from each other. It is safe to instantiate this class multiple times.

Type parameters

  • T

Hierarchy

  • AsyncLocalStorage

Index

Methods

disable

  • disable(): void
  • This method disables the instance of AsyncLocalStorage. All subsequent calls to asyncLocalStorage.getStore() will return undefined until asyncLocalStorage.run() is called again.

    When calling asyncLocalStorage.disable(), all current contexts linked to the instance will be exited.

    Calling asyncLocalStorage.disable() is required before the asyncLocalStorage can be garbage collected. This does not apply to stores provided by the asyncLocalStorage, as those objects are garbage collected along with the corresponding async resources.

    This method is to be used when the asyncLocalStorage is not in use anymore in the current process.

    Returns void

enterWith

  • enterWith(store: T): void
  • Calling asyncLocalStorage.enterWith(store) will transition into the context for the remainder of the current synchronous execution and will persist through any following asynchronous calls.

    Parameters

    • store: T

    Returns void

exit

  • exit<R>(callback: function, ...args: any[]): R
  • This methods runs a function synchronously outside of a context and return its return value. The store is not accessible within the callback function or the asynchronous operations created within the callback.

    Optionally, arguments can be passed to the function. They will be passed to the callback function.

    If the callback function throws an error, it will be thrown by exit too. The stacktrace will not be impacted by this call and the context will be re-entered.

    Type parameters

    • R

    Parameters

    • callback: function
        • (...args: any[]): R
        • Parameters

          • Rest ...args: any[]

          Returns R

    • Rest ...args: any[]

    Returns R

getStore

  • getStore(): T | undefined
  • This method returns the current store. If this method is called outside of an asynchronous context initialized by calling asyncLocalStorage.run, it will return undefined.

    Returns T | undefined

run

  • run<R>(store: T, callback: function, ...args: any[]): R
  • This methods runs a function synchronously within a context and return its return value. The store is not accessible outside of the callback function or the asynchronous operations created within the callback.

    Optionally, arguments can be passed to the function. They will be passed to the callback function.

    I the callback function throws an error, it will be thrown by run too. The stacktrace will not be impacted by this call and the context will be exited.

    Type parameters

    • R

    Parameters

    • store: T
    • callback: function
        • (...args: any[]): R
        • Parameters

          • Rest ...args: any[]

          Returns R

    • Rest ...args: any[]

    Returns R

Generated using TypeDoc