lbry-desktop/ui/util/fetch.js

20 lines
437 B
JavaScript
Raw Normal View History

import { FETCH_TIMEOUT } from 'constants/errors';
export default function fetchWithTimeout(ms, promise) {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
reject(new Error(FETCH_TIMEOUT));
}, ms);
promise.then(
(res) => {
clearTimeout(timeoutId);
resolve(res);
},
(err) => {
clearTimeout(timeoutId);
reject(err);
}
);
});
}