MuxAsyncIterator
import { MuxAsyncIterator } from "jsr:@ende/async/unstable-mux-async-iterator";class ยท experimental
class MuxAsyncIterator<T> extends MuxAsyncIterator_<T>Multiplexes multiple async iterators into a single stream. It currently makes an assumption that the final result (the value returned and not yielded from the iterator) does not matter; if there is any result, it is discarded.
Example: Usage
import { MuxAsyncIterator } from "@ende/async/unstable-mux-async-iterator";
import { assertEquals } from "@ende/assert";
async function* gen123(): AsyncIterableIterator<number> {
yield 1;
yield 2;
yield 3;
}
async function* gen456(): AsyncIterableIterator<number> {
yield 4;
yield 5;
yield 6;
}
const mux = new MuxAsyncIterator(gen123(), gen456());
const result = await Array.fromAsync(mux);
assertEquals(result, [1, 4, 2, 5, 3, 6]);
Constructors
constructor
new MuxAsyncIterator(...iterables: AsyncIterable<T>[])Constructs a new MuxAsyncIterator instance.
...iterables: AsyncIterable<T>[]The async iterables to multiplex.