lbry-desktop/ui/util/fetch.js

18 lines
386 B
JavaScript
Raw Normal View History

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);
}
);
});
}