@epikodelabs/streamix / createAsyncCoordinator
Function: createAsyncCoordinator()
createAsyncCoordinator(
sources?):AsyncCoordinator<any>
Defined in: projects/libraries/streamix/src/lib/utils/coordinator.ts:102
Creates an async coordinator that merges multiple async iterators.
The coordinator supports:
- Synchronous draining for sources that support it (via
__tryNext) - Concurrent async pulling for async sources
- Push notification support for sources with
__onPush - Dynamic addition and removal of sources during iteration
- Automatic cleanup and error propagation
The returned coordinator is itself an async iterator that yields RunnerEvent objects, indicating value, completion, or error from each source. The coordinator can be used in for await loops or manually via .next(). It also exposes methods for dynamic source management.
Parameters
sources?
AsyncIterator<any, any, any>[] = []
Initial array of async iterators (can be empty).
Returns
AsyncCoordinator<any>
An AsyncCoordinator with dynamic source management capabilities.
Example
ts
const coordinator = createAsyncCoordinator([stream1, stream2]);
for await (const event of coordinator) {
if (event.type === 'value') {
// event.value from event.sourceIndex
}
}