QUESTION: What is Promise.all?
The Promise.all method is a powerful tool for running multiple asynchronous operations in parallel in JavaScript. Syntactically, it accepts an iterable object, most commonly an array containing promises, such as in the construct Promise.all([p1, p2, p3]), and runs them simultaneously rather than sequentially. This dramatically improves application performance when you need to request independent data from multiple sources.
The main feature of this method is that it waits for all promises to settle before continuing execution of the subsequent code. When each of the passed promises resolves successfully, the method returns an array of results, where each element corresponds to the result of the original promise in the same order they were passed into the input array. This is very convenient for destructuring the received data, for example, when simultaneously loading a user profile, their list of orders, and interface settings.
However, this approach has a critical feature that must be considered when designing architecture: it rejects on the first error. If even one of the promises in the array fails (transitions to the rejected state), the entire Promise.all immediately stops waiting for the rest and returns that error. The remaining promises continue to run in the background, but their results will be ignored. Therefore, Promise.all is ideal for tasks where all requests are critically important for the screen to work, and partial success does not make sense.