Interface Context<T>

The generic Context object returned by createContext.

interface Context<T> {
    id: symbol;
    provide<R>(value: T, fn: (() => R | Promise<R>)): R | Promise<R>;
    require<K>(keys?: K[]): ITaskMiddlewareConfigured<{
        context: Context<T>;
    }, void, void, any>;
    use(): T;
}

Type Parameters

  • T

Properties

Methods

Properties

id: symbol

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>

  • Generates a middleware that guarantees the context exists (and optionally enforces that certain keys are present on the context object).

    Type Parameters

    • K extends string | number | symbol = never

    Parameters

    • Optionalkeys: K[]

    Returns ITaskMiddlewareConfigured<{
        context: Context<T>;
    }, void, void, any>