Promise.allSettled()
Promise.allSettled() waits until every Promise settles and returns each outcome as an object. Unlike Promise.all(), one rejected task does not fail the whole batch.
Overview
Promise.allSettled() waits until every Promise settles and returns each outcome as an object. Unlike Promise.all(), one rejected task does not fail the whole batch.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 76 | 79 | 71 | 13 | 76 | 13 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
const results = await Promise.allSettled([
fetch('/api/users'),
fetch('/api/posts'),
fetch('/api/comments'),
]);
const successful = results
.filter(r => r.status === 'fulfilled')
.map(r => r.value);
const failed = results
.filter(r => r.status === 'rejected')
.map(r => r.reason); Live demo
Success and failure. mixed
Multiple. task Run, each. complete individual to inspect it..
PreviewFullscreen
Successde-ta. only. Extract
onepart that error to also, read in de-taonly in processing continue rowexample..
PreviewFullscreen
Use cases
Batch requests with mixed outcomes
Load independent dashboard panels or resources together, then render whichever results succeeded.
End-of-run summaries
Collect every success and failure so a job report can show what needs retrying without losing successful work.
Cautions
- allSettled waits for the slowest Promise, so it is not ideal when you need to stop early after one useful result.
- The returned objects use different fields for fulfilled and rejected results, so branch carefully on status.
Accessibility
- If some tasks succeed while others fail, communicate both states clearly instead of announcing only a single generic result.
Related links
Powered by web-features