DEV Community

Discussion on: What's wrong with Promise.allSettled() and Promise.any()❓

Collapse
 
zakalwe314 profile image
Euan Smith • Edited

My typical use case is that I have a number of possible locations of a given resource. There may be multiple servers for the same thing (e.g. primary and backup, or different geographical locations). Some of these might fail, but you don't care so long as you can find one which succeeds. In this case Promise.any is the right pattern as it only rejects if ALL of the endpoints reject.

A second use case is that I have multiple routes to the same server. One might be a route via the internet and one might be locally over a LAN - both or neither of these routes might be available. Again Promise.any is the right pattern.

If what you do is work with cloud services then it is possible you will never need this - you don't have availability or routing complications. However I work with distributed services and IoT devices (we develop the hardware and the software) sometimes operating in networks with poor or otherwise limited connectivity. In this case Promise.any is an essential tool in establishing a connection.

Thread Thread
 
kimamula profile image
Kenji Imamula

Thanks for sharing! That makes sense.