Let\'s say I have a set of Promise
s that are making network requests, of which one will fail:
// http://does-not-exist will throw a TypeError
va
I had the same problem and have solved it in the following way:
const fetch = (url) => {
return node-fetch(url)
.then(result => result.json())
.catch((e) => {
return new Promise((resolve) => setTimeout(() => resolve(fetch(url)), timeout));
});
};
tasks = [fetch(url1), fetch(url2) ....];
Promise.all(tasks).then(......)
In that case Promise.all
will wait for every Promise will come into resolved
or rejected
state.
And having this solution we are "stopping catch
execution" in a non-blocking way. In fact, we're not stopping anything, we just returning back the Promise
in a pending state which returns another Promise
when it's resolved after the timeout.