Compose Promise Outcomes
Promise composition combines several eventual outcomes into a policy: require all successes, inspect every settled outcome, take the first settlement, or take the first fulfillment. The composition method does not automatically cancel other work.
Decide whether one failure should block the whole screen or whether successful panels can still be shown.
Choose a failure policy before choosing a method
A dashboard loads article titles and an optional recommendation panel. If the titles fail, the main page cannot do its job; a failed recommendation may be recoverable. Whether a failure is fatal is a product rule. Promise composition implements that rule; it does not decide it for you.
| Method | Resolves when | Rejects when | Empty input |
|---|---|---|---|
Promise.all |
Every input fulfills | An input rejects | Fulfills with [] |
Promise.allSettled |
Every input settles | Input rejections become result records | Fulfills with [] |
Promise.race |
The first input settles successfully | The first settlement is rejection | Remains pending |
Promise.any |
An input fulfills | All inputs reject, with AggregateError | Rejects with AggregateError |
promise Apromise Bpromise CThe callbacks produce two fulfilled titles and one rejected outcome. allSettled preserves input order in its result, regardless of settlement order. Every result has a status; access value only for a fulfilled result and reason for a rejected one. Promise.all also preserves input order for its fulfilled array. It does not serialize independent operations into one-at-a-time work.
Start times and await placement
Calling an async operation usually starts or initiates it before you put its returned promise into an array. await loadA(); await loadB(); starts B after A completes. Creating both promises first and then awaiting Promise.all can allow independent operations to proceed concurrently. Concurrency is not necessarily parallel JavaScript execution on several threads.
A rejection from Promise.all or a winner from race does not cancel the other requests or timers. A timeout implemented with race can stop waiting while the original request keeps working. Use the host's cancellation facility where available, and keep a stale-result guard when relevant.
Catch and finally do different jobs
A catch handler can recover by returning a value or keep the rejection by throwing. A finally callback runs on either settlement for cleanup. Returning an ordinary value from finally does not replace the earlier result, but throwing or returning a rejected promise can replace it with a rejection. Keep cleanup reliable; do not accidentally hide the original failure.
Predict, change and check
Replace allSettled with all and explain which caller must catch the rejection. Try an empty input. In the task, unsuccessful panels are intentionally omitted, while successful titles keep their original order. The requirement is partial recovery, not 'ignore every error' as a universal policy.