@jiminp/tooltool
    Preparing search index...

    Function pipeToAsyncSink

    • Consumes an async source, forwarding yields to sink.next(), its final return value to sink.complete(), and failures advancing the source to sink.error().

      Type Parameters

      • Y

        Yielded value type.

      • R = void

        Final return value type.

      • T = unknown

        Thrown error type.

      Parameters

      • source: AsyncIterable<Y, R, any> | AsyncIterator<Y, R, any>

        Async iterable or iterator to consume.

      • sink: AsyncSink<Y, R, T>

        Destination for values and notifications.

      Returns Promise<void>

      Resolves after source completion or an error has been delivered to the sink.

      Propagates exceptions from sink methods or obtaining the source iterator.

      Sink methods run synchronously and are not awaited. A source error is handled by sink.error() and does not itself reject the returned promise; a throwing sink method does reject it and stops piping.

      const sink: AsyncSink<number, void> = {
      next: (n) => console.log(`Value: ${n}`),
      complete: () => console.log('Done!'),
      error: (err) => console.error('Error:', err),
      };

      async function* gen() {
      yield 1;
      yield 2;
      yield 3;
      }

      await pipeToAsyncSink(gen(), sink);
      // Logs: "Value: 1", "Value: 2", "Value: 3", "Done!"