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.
Stream element type
Callback return type
The ReadableStream to consume
Callback function applied to each chunk
Promise resolving to array of all callback results
const results = await consumeStream(numberStream, (n) => n * 2);console.log(results); // [2, 4, 6, 8, ...] Copy
const results = await consumeStream(numberStream, (n) => n * 2);console.log(results); // [2, 4, 6, 8, ...]
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.