UNPKG

664 BJavaScriptView Raw
1import { TimeoutError } from '../errors/TimeoutError.js';
2// `Promise.race()` workaround (#91)
3export const timeout = async (request, abortController, options) => new Promise((resolve, reject) => {
4 const timeoutId = setTimeout(() => {
5 if (abortController) {
6 abortController.abort();
7 }
8 reject(new TimeoutError(request));
9 }, options.timeout);
10 void options
11 .fetch(request)
12 .then(resolve)
13 .catch(reject)
14 .then(() => {
15 clearTimeout(timeoutId);
16 });
17});
18export const delay = async (ms) => new Promise(resolve => {
19 setTimeout(resolve, ms);
20});
21//# sourceMappingURL=time.js.map
\No newline at end of file