botbook/node_modules/ky/distribution/utils/timeout.js
Rodrigo Rodriguez 6ae15fe3e5 Updated.
2024-09-04 13:13:15 -03:00

20 lines
No EOL
662 B
JavaScript

import { TimeoutError } from '../errors/TimeoutError.js';
// `Promise.race()` workaround (#91)
export default async function timeout(request, init, abortController, options) {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
if (abortController) {
abortController.abort();
}
reject(new TimeoutError(request));
}, options.timeout);
void options
.fetch(request, init)
.then(resolve)
.catch(reject)
.then(() => {
clearTimeout(timeoutId);
});
});
}
//# sourceMappingURL=timeout.js.map