Documentation / @agentick/core / mergeStreams
Function: mergeStreams() ​
mergeStreams<
T>(input):AsyncIterable<T|StreamTag<T>>
Defined in: kernel/src/stream.ts:145
Merge multiple async streams into a single stream, yielding items as they arrive.
Supports two input formats:
- Array: Returns items directly (type
T) - Record: Returns tagged items with source key (type
StreamTag<T>)
Handles context propagation, backpressure, and cleanup of all iterators.
Type Parameters ​
T ​
T
Item type
Parameters ​
input ​
Array of streams or Record mapping names to streams
Record<string, AsyncIterable<T, any, any>> | AsyncIterable<T, any, any>[]
Returns ​
AsyncIterable<T | StreamTag<T>>
Merged stream of items (or tagged items for Record input)
Examples ​
typescript
const merged = mergeStreams([stream1, stream2, stream3]);
for await (const item of merged) {
console.log(item); // Items from any stream, in arrival order
}typescript
const tagged = mergeStreams({ a: stream1, b: stream2 });
for await (const item of tagged) {
console.log(item.source, item.value); // 'a' or 'b', plus the value
}