deno.land / x / replicache@v10.0.0-beta.0 / sleep.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
import {AbortError} from './abort-error';
/** * Creates a promise that resolves after [[ms]] milliseconds. Note that if you * pass in `0` no `setTimeout` is used and the promise resolves immediately. In * other words no macro task is used in that case. * * Pass in an AbortSignal to clear the timeout. */export function sleep(ms: number, signal?: AbortSignal): Promise<void> { if (ms === 0) { return Promise.resolve(); }
return new Promise((resolve, reject) => { const id = setTimeout(() => { resolve(); }, ms);
if (signal) { signal.addEventListener('abort', () => { if (id) { clearTimeout(id); } reject(new AbortError('Aborted')); }); } });}
replicache

Version Info

Tagged at
2 years ago