UNPKG

771 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 /* eslint-disable promise/prefer-await-to-then */
11 void options
12 .fetch(request)
13 .then(resolve)
14 .catch(reject)
15 .then(() => {
16 clearTimeout(timeoutID);
17 });
18 /* eslint-enable promise/prefer-await-to-then */
19});
20export const delay = async (ms) => new Promise(resolve => {
21 setTimeout(resolve, ms);
22});
23//# sourceMappingURL=time.js.map
\No newline at end of file