Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
class MuxAsyncIterator
implements AsyncIterable<T>
import { MuxAsyncIterator } from "https://deno.land/std@0.220.1/async/mux_async_iterator.ts";

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.

Examples

Example 1

import { MuxAsyncIterator } from "https://deno.land/std@0.220.1/async/mux_async_iterator.ts";

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<number>();
mux.add(gen123());
mux.add(gen456());
for await (const value of mux) {
  // ...
}
// ..

Methods

add(iterable: AsyncIterable<T>)

Add an async iterable to the stream.

iterate(): AsyncIterableIterator<T>

Returns an async iterator of the stream.

[Symbol.asyncIterator](): AsyncIterator<T>

Implements an async iterator for the stream.