Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What are the differences between Promise.all() and Promise.any() in JavaScript?

When working with the Promise object in JavaScript, I noticed two methods, which were Promise.all() and Promise.any().

Both of them take an iterable (such as an array) as a parameter. However, I can’t find what each method does differently.

After searching it on MDN, it was still hard to find a summary for the differences between the two methods.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In conclusion, what are the differences between Promise.all() and Promise.any() in JavaScript?


Note: This question is not related to this question. Instead of Promise.race(), I am asking about Promise.all().

>Solution :

Promise.all only resolves when all Promises in the array passed in are resolved, and returns the array of resolved Promises.

Promise.any resolves when any Promise in the array passed in, and returns the first Promise to do so.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading