tee
import { tee } from "jsr:@ende/async";function
function tee<T, N extends number = 2>(iterable: AsyncIterable<T>, n: N = [UNSUPPORTED]): Tuple<AsyncIterable<T>, N>Branches the given async iterable into the n branches.
iterable: AsyncIterable<T>The iterable to tee.
n: N = [UNSUPPORTED]The amount of branches to tee into.
Returns
The tuple where each element is an async iterable.
Example: Usage
import { tee } from "@ende/async/tee";
import { assertEquals } from "@ende/assert";
const gen = async function* gen() {
yield 1;
yield 2;
yield 3;
};
const [branch1, branch2] = tee(gen());
const result1 = await Array.fromAsync(branch1);
assertEquals(result1, [1, 2, 3]);
const result2 = await Array.fromAsync(branch2);
assertEquals(result2, [1, 2, 3]);