1 | import { TimeoutError } from '../errors/TimeoutError.js';
|
2 |
|
3 | export 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 | });
|
18 | export const delay = async (ms) => new Promise(resolve => {
|
19 | setTimeout(resolve, ms);
|
20 | });
|
21 |
|
\ | No newline at end of file |