lbry-desktop/ui/util/fetch.js
2020-03-16 17:59:24 -04:00

17 lines
386 B
JavaScript

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