This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
48 lines (43 loc) · 1.38 KB
/
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
// Copyright 2020 Yoshiya Hinosawa. All rights reserved. MIT license.
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { mux } from "./mod.ts";
function defer(n: number) {
return new Promise((resolve, _) => setTimeout(resolve, n));
}
async function* foo() {
await defer(10);
yield 10;
await defer(30);
yield 40;
await defer(30);
yield 70;
}
async function* bar() {
await defer(20);
yield 20;
await defer(30);
yield 50;
await defer(30);
yield 80;
}
async function* baz() {
await defer(30);
yield 30;
await defer(30);
yield 60;
await defer(30);
yield 90;
}
Deno.test("mux returns an async iterator that merges the given async iterators.", async () => {
const iter = mux(foo(), bar(), baz());
assertEquals(await iter.next(), { done: false, value: 10 });
assertEquals(await iter.next(), { done: false, value: 20 });
assertEquals(await iter.next(), { done: false, value: 30 });
assertEquals(await iter.next(), { done: false, value: 40 });
assertEquals(await iter.next(), { done: false, value: 50 });
assertEquals(await iter.next(), { done: false, value: 60 });
assertEquals(await iter.next(), { done: false, value: 70 });
assertEquals(await iter.next(), { done: false, value: 80 });
assertEquals(await iter.next(), { done: false, value: 90 });
assertEquals(await iter.next(), { done: true, value: undefined });
});