Coordinating multiple promises
Promise combinators describe how a group of delayed operations should finish together.
How it works
Pick the result that matches the user experience. When a page needs both profile and settings before it can render, Promise.all represents that requirement. For independent panels that can show partial success, allSettled gives you each outcome so successful content can still appear.
Walk through an example
Promise.all becomes ready when all results succeed and returns them in input order. Promise.allSettled waits for every outcome, including failures.
What to watch for
A rejection from Promise.all does not automatically cancel the other operations. Arrange cancellation separately if those operations support it.
Code example
const results = Promise.all([Promise.resolve('A'), Promise.resolve('B')]);
results.then(values => console.log(values.join(', ')));Check your understanding
In what order do the results appear?
See the example and explanation
- Worked example
- Given
Promise.all receives A first and B second. B finishes before A. - Answer
A, B
The result positions match the input positions, even when completion order is different.