Let’s consider another scenario: You have to build an API that gets information from multiple third-party APIs and aggregates all the responses from the APIs. catch(error => console.log(`Error in promises $`)) // Catch the error. Then, Promise.all itself as a promise will get resolved once all the ten promises get resolved or any of the ten promises get rejected with an error. So you are passing all ten promises to Promise.all. You have to know when all the promises get resolved or you have to wait till all the promises resolve. Then it gets resolved when all the promises get resolved or any one of them gets rejected.įor example, assume that you have ten promises (Async operation to perform a network call or a database connection). Promise.all is actually a promise that takes an array of promises as an input (an iterable).
You have to know what is a Promise in JavaScript. In other words, I can say that it helps you to do concurrent operations (sometimes for free). Promise.all takes Async operations to the next new level as it helps you to aggregate a group of promises. Promises in JavaScript are one of the powerful APIs that help us to do Async operations.