@jiminp/tooltool
    Preparing search index...

    Interface AsyncSource<Y, R, E>

    Read-side of an async channel that consumes values via iteration or callbacks.

    Implements AsyncIterable, so it can be consumed with for await...of. Each iterator returned by [Symbol.asyncIterator]() replays from the beginning of the buffered events independently.

    declare const source: AsyncSource<number, string>;

    for await (const v of source) console.log(v);
    console.log(await source.result());
    interface AsyncSource<Y, R = void, E = unknown> {
        onReturn(callback: (ret: R) => void): void;
        onThrow(callback: (err: E) => void): void;
        onYield(callback: (y: Y) => void): void;
        result(): Promise<R>;
        subscribe(callback: (event: AsyncEvent<Y, R, E>) => void): void;
    }

    Type Parameters

    • Y

      Yielded value type.

    • R = void

      Return value type.

    • E = unknown

      Error type (default: unknown).

    Hierarchy (View Summary)

    Index
    • Subscribes to the return value only, with the callback policy of subscribe.

      Parameters

      • callback: (ret: R) => void

      Returns void

    • Subscribes to thrown errors only, with the callback policy of subscribe.

      Parameters

      • callback: (err: E) => void

      Returns void

    • Subscribes to yielded values only, with the callback policy of subscribe.

      Parameters

      • callback: (y: Y) => void

      Returns void

    • Returns a promise that resolves with the channel's return value, or rejects with its error. Repeated calls return the same promise without consuming buffered events.

      Returns Promise<R>

    • Subscribes to all events (yield, return, and throw) as they arrive.

      Parameters

      Returns void

      Immediately flushes any already-buffered events to callback, then continues to deliver new events in order. Callbacks run synchronously and are not awaited. A throwing callback is detached: during replay its exception propagates from this call; for new events, all pending consumers are notified before the producer receives the first callback exception. Channel completion and errors are unaffected.