deno.land / std@0.91.0 / async / mux_async_iterator_test.ts

mux_async_iterator_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2018-2021 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", ); },});
std

Version Info

Tagged at
3 years ago

External Dependencies

No external dependencies 🎉