@adviser/cement - v0.0.0
    Preparing search index...

    Function consumeStream

    • Consumes a ReadableStream, applying a callback to each chunk and collecting results.

      Processes each chunk through the callback and returns an array of all results. Waits for async callbacks to complete before processing the next chunk.

      Type Parameters

      • E

        Stream element type

      • R

        Callback return type

      Parameters

      • stream: ReadableStream<E>

        The ReadableStream to consume

      • cb: (msg: E) => R

        Callback function applied to each chunk

      Returns Promise<R[]>

      Promise resolving to array of all callback results

      const results = await consumeStream(numberStream, (n) => n * 2);
      console.log(results); // [2, 4, 6, 8, ...]