We have a parallel promise call:- promise.all([p1,p2]).then().catch() here p1,p2 are 2 different promise calls .
- p1 - reject for some condition and show e1
- p2 - reject for some condition and show e2
- p1 - resolve then do something
- p2 - do not resolve
p1,p2 reject conditions are different .
If p1,p2 both reject , we show e2
Now suppose both reject but p1 rejects first , how to handle this and show e2 ?
p90 for p1 > p90 for p2 but there can be the edge cases if p1 happens earlier than p2 , hence the query .
Tried using promise.allSettled but it had other issues where p2 executed after the .then block ran for 2 times (there were 2 promise and corresponding array elements in the results ).
We have tried multiple things , resolving with a particular error message in case of p1 failure but it does not work .
(Preface: Promise terminology can be confusing and most people use it incorrect. My blog post on terminology may be a useful read.)
You were right to look at
Promise.allSettled. If you want to do X when one promise is fulfilled and another is rejected, that's the way to go; you get an array of the results, rather thanPromise.all's behavior of short-circuiting if any of the input promises is rejected.It's not clear what you mean by that, but if you mean you need to do something if
p2doesn't settle (get fulfilled or rejected) within a certain period of time, you probably want to usePromise.racewith a timeout promise.Without code it's hard to help you, but here's an example of combining
Promise.allSettledwithPromise.race:Live Example: