deno.land / std@0.166.0 / async / delay_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { delay } from "./delay.ts";import { assert, assertRejects } from "../testing/asserts.ts";
Deno.test("[async] delay", async function () { const start = new Date(); const delayedPromise = delay(100); const result = await delayedPromise; const diff = new Date().getTime() - start.getTime(); assert(result === undefined); assert(diff >= 100);});
Deno.test("[async] delay with abort", async function () { const start = new Date(); const abort = new AbortController(); const { signal } = abort; const delayedPromise = delay(100, { signal }); setTimeout(() => abort.abort(), 0); await assertRejects( () => delayedPromise, DOMException, "Delay was aborted", );
const diff = new Date().getTime() - start.getTime(); assert(diff < 100);});
Deno.test("[async] delay with non-aborted signal", async function () { const start = new Date(); const abort = new AbortController(); const { signal } = abort; const delayedPromise = delay(100, { signal }); // abort.abort() const result = await delayedPromise; const diff = new Date().getTime() - start.getTime(); assert(result === undefined); assert(diff >= 100);});
Deno.test("[async] delay with signal aborted after delay", async function () { const start = new Date(); const abort = new AbortController(); const { signal } = abort; const delayedPromise = delay(100, { signal }); const result = await delayedPromise; abort.abort(); const diff = new Date().getTime() - start.getTime(); assert(result === undefined); assert(diff >= 100);});
Deno.test("[async] delay with already aborted signal", async function () { const start = new Date(); const abort = new AbortController(); abort.abort(); const { signal } = abort; const delayedPromise = delay(100, { signal }); await assertRejects( () => delayedPromise, DOMException, "Delay was aborted", );
const diff = new Date().getTime() - start.getTime(); assert(diff < 100);});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago