TL;DR: I'm looking for a strategy or an example of handling an unknown amount of promise rejections and retrying them an X
amount of time when using Promise.allSettled()
for multiple async calls.
After reading this article: https://www.coreycleary.me/better-handling-of-rejections-using-promise-allsettled I got pretty excited by this sentence:
This is great because we can still load the user account info, and retry fetching the user activity later. (retries are outside the scope of this post, and there are multiple strategies for that)
However, when researching online I found absolutely none concrete examples, or even posts that deal with this issue directly.
Here is some example code:
public async test() {
try {
console.log('trying..');
const multiAsync = [this.somethingA(), this.somethingB(), this.somethingC()];
const [a, b, c] = await Promise.allSettled(multiAsync);
} catch (e) {
console.log('catch');
console.log(e);
}
}
Now lets say for the above code, both A and C failed, and I want to retry them, let's say- just one more time.
Even Though I have a, b, c
, I only know which is fullfilled:true
and which are not. but I don't know to link a
back to somethingA()
and c
to somethingC()
to retry only those 2 functions, and I definitely don't want to invoke somethingB()
twice..
Any ideas?