@jiminp/tooltool
    Preparing search index...

    Function pipeToAsyncSink

    • Pipes values from an async source to an async sink, forwarding all yielded values, the final return value, and any errors that occur.

      Consumes the source and calls the appropriate sink methods: next() for each yielded value, complete() when the source finishes successfully, and error() if the source throws.

      Type Parameters

      • Y

        The type of values yielded by the source

      • R = void

        The type of the final return value

      • T = unknown

        The type of errors that may be thrown

      Parameters

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

        The async iterable or iterator to consume

      • sink: AsyncSink<Y, R, T>

        The destination sink that receives values and notifications

      Returns Promise<void>

      A promise that resolves when the piping operation completes

      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!"