mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 20:59:10 +00:00
parent
b1893e65f2
commit
490d2a5ca1
2 changed files with 44 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { assertEquals } from "../testing/asserts.ts";
|
||||
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
|
||||
import { MuxAsyncIterator } from "./mux_async_iterator.ts";
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
|
@ -16,6 +16,12 @@ async function* gen456(): AsyncIterableIterator<number> {
|
|||
yield 6;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
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());
|
||||
|
@ -26,3 +32,22 @@ Deno.test("[async] MuxAsyncIterator", async function (): Promise<void> {
|
|||
}
|
||||
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"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue