-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathtimeout-spec.ts
More file actions
54 lines (48 loc) · 1.59 KB
/
timeout-spec.ts
File metadata and controls
54 lines (48 loc) · 1.59 KB
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
52
53
54
import { hasNext, hasErr, noNext, delayValue } from '../asynciterablehelpers.js';
import { timeout, finalize } from 'ix/asynciterable/operators/index.js';
import { as } from 'ix/asynciterable/index.js';
import { TimeoutError } from 'ix/asynciterable/operators/timeout.js';
test('AsyncIterable#timeout drops none', async () => {
const xs = async function* () {
yield await delayValue(1, 500);
yield await delayValue(2, 500);
yield await delayValue(3, 500);
};
const ys = as(xs()).pipe(timeout(1000));
const it = ys[Symbol.asyncIterator]();
await hasNext(it, 1);
await hasNext(it, 2);
await hasNext(it, 3);
await noNext(it);
});
test('AsyncIterable#timeout throws when delayed', async () => {
const xs = async function* () {
yield await delayValue(1, 500);
yield await delayValue(2, 2000);
};
const ys = as(xs()).pipe(timeout(1000));
const it = ys[Symbol.asyncIterator]();
await hasNext(it, 1);
await hasErr(it, TimeoutError);
await noNext(it);
});
// eslint-disable-next-line jest/no-disabled-tests -- See https://github.com/ReactiveX/IxJS/pull/379#issuecomment-2611883590
test.skip('AsyncIterable#timeout triggers finalize', async () => {
let done = false;
const xs = async function* () {
yield await delayValue(1, 500);
yield await delayValue(2, 2000);
};
const ys = as(xs()).pipe(
finalize(() => {
done = true;
}),
timeout(1000)
);
const it = ys[Symbol.asyncIterator]();
await hasNext(it, 1);
await hasErr(it, TimeoutError);
await noNext(it);
await new Promise((res) => setTimeout(res, 10));
expect(done).toBeTruthy();
});