@jiminp/tooltool
    Preparing search index...

    Interface AsyncChannel<Y, R, E>

    Bidirectional async channel combining AsyncSink and AsyncSource.

    Provides a write-side for pushing values and a read-side for consuming them via async iteration or event callbacks.

    declare const ch: AsyncChannel<number, string>;
    ch.next(1);
    ch.next(2);
    ch.complete("done");

    for await (const v of ch) console.log(v); // 1, 2
    console.log(await ch.result()); // "done"
    interface AsyncChannel<Y, R = void, E = unknown> {
        complete(...args: OptionalIfVoid<R>): void;
        error(err: E): void;
        next(y: Y): void;
        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
    • 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.