deno.land / x / ky@v0.31.3 / source / utils / time.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
import {TimeoutError} from '../errors/TimeoutError.js';
export type TimeoutOptions = { timeout: number; fetch: typeof fetch;};
// `Promise.race()` workaround (#91)export const timeout = async ( request: Request, abortController: AbortController | undefined, options: TimeoutOptions,): Promise<Response> => new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { if (abortController) { abortController.abort(); }
reject(new TimeoutError(request)); }, options.timeout);
void options .fetch(request) .then(resolve) .catch(reject) .then(() => { clearTimeout(timeoutId); }); });
export const delay = async (ms: number) => new Promise(resolve => { setTimeout(resolve, ms);});
ky

Version Info

Tagged at
a year ago