async function fetchWithTimeout(resource, options = {}) {
const { timeout = 8000 } = options;
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
const response = await fetch(resource, {
...options,
signal: controller.signal
});
clearTimeout(id);
return response;
}
function timeoutFetch(promise) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
reject(new Error("timeout"))
}, 5000)
promise.then(resolve, reject)
})
}