AIDK API Reference / aidk-kernel / mergeStreams
Function: mergeStreams() ​
ts
function mergeStreams<T>(input:
| AsyncIterable<T, any, any>[]
| Record<string, AsyncIterable<T, any, any>>): AsyncIterable<T | StreamTag<T>>;Defined in: packages/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 ​
| Type Parameter | Description |
|---|---|
T | Item type |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
input | | AsyncIterable<T, any, any>[] | Record<string, AsyncIterable<T, any, any>> | Array of streams or Record mapping names to streams |
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
}