The generic AsyncContext object returned by defineAsyncContext.

interface IAsyncContext<T> {
    [symbolAsyncContext]: true;
    id: string;
    optional(): IOptionalDependency<IAsyncContext<T>>;
    parse(data: string): T;
    provide<R>(value: T, fn: (() => R | Promise<R>)): R | Promise<R>;
    require<K>(keys?: K[]): ITaskMiddlewareConfigured<{
        context: IAsyncContext<T>;
    }, void, void, any>;
    serialize(data: T): string;
    use(): T;
}

Type Parameters

  • T

Properties

[symbolAsyncContext]: true

Brand marker for registration and runtime checks

id: string

unique symbol used as key in the AsyncLocalStorage map

Methods

  • Provide a value for this context during the lifetime of fn()

    Type Parameters

    • R

    Parameters

    • value: T
    • fn: (() => R | Promise<R>)
        • (): R | Promise<R>
        • Returns R | Promise<R>

    Returns R | Promise<R>