UNPKG

@smeijer/ky

Version:

Tiny and elegant HTTP client based on the Fetch API

23 lines 775 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = timeout; const TimeoutError_js_1 = require("../errors/TimeoutError.js"); // `Promise.race()` workaround (#91) async function timeout(request, init, abortController, options) { return new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { if (abortController) { abortController.abort(); } reject(new TimeoutError_js_1.TimeoutError(request)); }, options.timeout); void options .fetch(request, init) .then(resolve) .catch(reject) .then(() => { clearTimeout(timeoutId); }); }); } //# sourceMappingURL=timeout.js.map