mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
9029003046
Update prebuilt "dlint" binary to v0.2.10 and fix diagnostics for "require-await" rule. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
|
|
import { MuxAsyncIterator } from "./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;
|
|
}
|
|
|
|
async function* genThrows(): AsyncIterableIterator<number> {
|
|
yield 7;
|
|
throw new Error("something went wrong");
|
|
}
|
|
|
|
Deno.test("[async] MuxAsyncIterator", async function (): Promise<void> {
|
|
const mux = new MuxAsyncIterator<number>();
|
|
mux.add(gen123());
|
|
mux.add(gen456());
|
|
const results = new Set();
|
|
for await (const value of mux) {
|
|
results.add(value);
|
|
}
|
|
assertEquals(results.size, 6);
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[async] MuxAsyncIterator throws",
|
|
async fn() {
|
|
const mux = new MuxAsyncIterator<number>();
|
|
mux.add(gen123());
|
|
mux.add(genThrows());
|
|
const results = new Set();
|
|
await assertThrowsAsync(
|
|
async () => {
|
|
for await (const value of mux) {
|
|
results.add(value);
|
|
}
|
|
},
|
|
Error,
|
|
"something went wrong",
|
|
);
|
|
},
|
|
});
|