std/async/unstable_mux_async_iterator_test.ts
scarf c221924aec
feat(async/unstable): accept iterator varargs in MuxAsyncIterator (#6087)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2024-10-08 23:20:01 +09:00

23 lines
669 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { MuxAsyncIterator } from "./unstable_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;
}
Deno.test("(unstable) MuxAsyncIterator() works with constructor iterables", async () => {
const mux = new MuxAsyncIterator(gen123(), gen456());
const results = new Set(await Array.fromAsync(mux));
assertEquals(results.size, 6);
assertEquals(results, new Set([1, 4, 2, 5, 3, 6]));
});