Class AlsExecutionContextAdapter<TValue>

IMPORT_PATH: "@daiso-tech/core/execution-context/als-execution-context-adapter"

Execution context adapter using Node.js AsyncLocalStorage.

This adapter implements context storage using Node.js's AsyncLocalStorage API, which provides automatic context propagation across async boundaries. It ensures context values are maintained correctly through promises, callbacks, and other asynchronous operations.

Recommended for Node.js environments where async context isolation is needed.

Type Parameters

  • TValue

Implements

Constructors

Methods

Constructors

Methods

  • Executes the given function within the specified context.

    This method ensures the provided context is active during function execution, making it accessible to get() calls within the function and any nested function calls. When the function completes, the previous context (if any) is restored.

    Useful for:

    • Maintaining context across async boundaries
    • Isolating context between concurrent executions
    • Implementing per-request or per-task metadata propagation

    Note: This method is used for both asynchronous and synchronous execution.

    Type Parameters

    • TReturn

      The return type of the function

    Parameters

    • context: TValue

      The context value to set for the duration of the function execution

    • fn: InvokableFn<[], TReturn>

      The function to execute within the context

    Returns TReturn

    The return value of the executed function

    Error propagated from the executed function