@jiminp/tooltool
    Preparing search index...

    Function createAsyncChannel

    • Creates an async channel that buffers values and replays them to each iterator.

      Type Parameters

      • Y

        Yielded value type.

      • R = void

        Return value type.

      • T = unknown

        Thrown error type (default: unknown).

      Returns AsyncChannel<Y, R, T>

      An AsyncChannel.

      Each call to [Symbol.asyncIterator]() returns a fresh iterator starting from the first buffered value. Calling result() multiple times returns the same promise without affecting iteration.

      const ch = createAsyncChannel<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"