mergeStreams
mergeStreams<
T>(…streams):ReadableStream<T>
Defined in: stream-utils.ts:292
Merge multiple ReadableStreams into a single stream.
This utility combines multiple source streams into one output stream, reading from all sources concurrently and emitting chunks as they arrive from any source. The merged stream closes when all source streams complete. Useful for combining multiple AI model responses or parallel data sources.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”streams
Section titled “streams”…ReadableStream<T>[]
Variable number of ReadableStreams to merge
Returns
Section titled “Returns”ReadableStream<T>
Single ReadableStream emitting chunks from all sources
Example
Section titled “Example”const stream1 = fetch('/api/model1').then(r => r.body!);const stream2 = fetch('/api/model2').then(r => r.body!);const combined = mergeStreams(stream1, stream2);
for await (const chunk of toAsyncIterable(combined)) { console.log('Chunk from either stream:', chunk);}