Documentation
    Preparing search index...

    Interface Scope

    A hierarchical cancellation scope.

    • Disposing a parent scope cancels all of its children.
    • Disposal is idempotent.
    • Inside Scope.run, any async tasks should use Scope.signal.
    • Developer diagnostics can flag dangling tasks, missing signal usage, and trace scope lifetime.
    interface Scope {
        disposed: boolean;
        parent?: Scope;
        signal: AbortSignal;
        all<T>(promises: Promise<T>[]): Promise<T[]>;
        child(opts?: { label?: string }): Scope;
        dispose(reason?: DisposeReason): void;
        fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
        onDispose(fn: () => void): void;
        race<T>(promises: Promise<T>[]): Promise<T>;
        run<T>(fn: (s: Scope) => T | Promise<T>): Promise<T>;
        timeout(ms: number, reason?: string): AbortSignal;
    }
    Index

    Properties

    disposed: boolean

    Whether this scope has been disposed (canceled).

    parent?: Scope

    Optional parent scope.

    signal: AbortSignal

    The cancellation signal to pass along to operations.

    Methods

    • Run multiple promises under this scope and await all.

      Type Parameters

      • T

      Parameters

      • promises: Promise<T>[]

        Array of promises to await.

      Returns Promise<T[]>

    • Create a child scope that will be canceled when this scope is.

      Parameters

      • Optionalopts: { label?: string }
        • Optionallabel?: string

          Optional identifier for diagnostics.

      Returns Scope

    • Like fetch, but automatically merges this scope’s signal with user-supplied ones.

      Parameters

      • input: RequestInfo | URL

        Request input.

      • Optionalinit: RequestInit

        Optional fetch init opts.

      Returns Promise<Response>

    • Register a callback to run when the scope is disposed.

      Parameters

      • fn: () => void

      Returns void

    • Run a promise race under this scope.

      Type Parameters

      • T

      Parameters

      • promises: Promise<T>[]

        Array of promises to race.

      Returns Promise<T>

    • Run a callback within this scope. Disposes if cancellation occurs.

      Type Parameters

      • T

      Parameters

      • fn: (s: Scope) => T | Promise<T>

        Function that receives the current scope.

      Returns Promise<T>

    • Returns a signal that aborts after the given timeout or when the scope aborts.

      Parameters

      • ms: number

        Timeout duration in milliseconds.

      • Optionalreason: string

        Optional reason for the timeout.

      Returns AbortSignal