Suggest an editImprove this articleRefine the answer for “Promise.allSettled() in JavaScript”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`Promise.allSettled()` takes an array (or any other iterable) of promises and returns a new promise that settles once every passed promise has settled, no matter whether it succeeded (`fulfilled`) or failed (`rejected`). That promise always becomes `fulfilled` and yields an array of `{status, value}` or `{status, reason}` objects, that is, a full report on every item. Unlike `Promise.all()`, it never falls over on the first error.** ```javascript Promise.allSettled([Promise.resolve('OK'), Promise.reject('Error')]) .then(console.log); // [{ status: "fulfilled", value: "OK" }, { status: "rejected", reason: "Error" }] ``` **Key point:** `all()` is all or nothing, `allSettled()` is a report on everything: use it when you must wait for every operation and see exactly what broke.Shown above the full answer for quick recall.Answer (EN)Image**`Promise.allSettled()` is a static method that takes an array (or any other iterable) of promises and returns a new promise which fulfills once every passed promise has settled.** It does not matter whether they succeeded (`fulfilled`) or failed (`rejected`): the method waits for *all results*, not only the successful ones. ## Theory ### TL;DR - `Promise.allSettled(iterable)` waits until **all** promises settle in any way. - The returned promise **always** becomes `fulfilled`, it never rejects. - Its value is an array of `{status, value}` or `{status, reason}` objects in input order. - `Promise.all()`, by contrast, rejects on the very first `reject` and loses the remaining results. - Typical use: bulk data loading, parallel validation, batched request sending. ### Quick example ```javascript const p1 = Promise.resolve('Success'); const p2 = Promise.reject('Error'); const p3 = Promise.resolve('One more'); Promise.allSettled([p1, p2, p3]) .then(results => console.log(results)); ``` Output: ```javascript [ { status: "fulfilled", value: "Success" }, { status: "rejected", reason: "Error" }, { status: "fulfilled", value: "One more" } ] ``` Every promise settled, the method did not "fall over", it returned a full summary: who succeeded and who failed. Syntax: ```javascript Promise.allSettled(iterable) ``` It returns a new promise that **always** ends up `fulfilled` and yields an **array of objects** with the results. ### Shape of the result Every element of the array is an object with the same set of fields: | Field | When it appears | Value | | --- | --- | --- | | `status` | always | `"fulfilled"` or `"rejected"` | | `value` | if `fulfilled` | the promise result | | `reason` | if `rejected` | the failure reason | The element order matches the order of the input promises, so a result is easy to map back onto the original list by index. ### When to use Promise.allSettled() - When it matters that you **wait for all operations to finish**, even if some of them fail. - When you need to collect **all results and errors together**, in one report. - For example, during **bulk data loading**, **parallel validation**, **batched request sending**, **data cleanup** and so on. ### How it differs from Promise.all() | Characteristic | `Promise.all()` | `Promise.allSettled()` | | --- | --- | --- | | When it settles | Only if **all promises succeed** | When **all promises settle** (with any outcome) | | What it returns | An array of `value` results | An array of `{status, value/reason}` objects | | Behaviour on failure | Falls over on the first `reject` | Does not fall over, waits for everyone | | State of the returned promise | Can be `fulfilled` or `rejected` | Always `fulfilled` | | What it is used for | When everything has to succeed | When you need a report on all results | A side by side example: ```javascript const a = Promise.resolve('A'); const b = Promise.reject('Error'); const c = Promise.resolve('C'); // Promise.all Promise.all([a, b, c]) .then(console.log) .catch(err => console.error('Promise.all:', err)); // Promise.allSettled Promise.allSettled([a, b, c]) .then(console.log); ``` Output: ```javascript Promise.all: Error [ { status: 'fulfilled', value: 'A' }, { status: 'rejected', reason: 'Error' }, { status: 'fulfilled', value: 'C' } ] ``` `Promise.all()` stopped at the error, while `Promise.allSettled()` waited for everyone and returned the full report. ### A practical example Imagine you need to load data from several sources, and even if one of them is unavailable, you still need the rest: ```javascript const urls = ['/user', '/posts', '/comments']; const requests = urls.map(url => fetch(url)); Promise.allSettled(requests) .then(results => { results.forEach((res, i) => { if (res.status === 'fulfilled') { console.log(`${urls[i]}: OK`); } else { console.warn(`${urls[i]}: failed`); } }); }); ``` This way you get a **summary across all requests**, even if one of them "fell over". A simple analogy: > Imagine you ordered three deliveries: > > - `Promise.all()`: if even one delivery does not arrive, you **get upset right away** and stop waiting for the others. > - `Promise.allSettled()`: you **wait for every courier**, even if one shows up without a parcel, so that you know **what happened to each delivery**. Summary table: | Method | Behaviour on failure | Return value | When it settles | | --- | --- | --- | --- | | `Promise.all()` | Falls over on the first `reject` | An array of successful values | When **all succeed** | | `Promise.allSettled()` | Never falls over | An array of `{status, value/reason}` | When **all are settled** | ### Common mistakes - **Attaching `.catch()` and expecting it to fire.** The promise from `allSettled()` does not reject, so failures must be looked up in the array elements whose `status === 'rejected'`, otherwise a breakage goes unnoticed. - **Mixing up `value` and `reason`.** A rejected element has no `value`, a fulfilled one has no `reason`: check `status` first. - **Thinking `allSettled()` makes code resilient by itself.** It only collects a report, the retry or degradation logic is still yours to write. - **Forgetting about HTTP errors in `fetch`.** `fetch` rejects only on a network failure, so a 500 response lands in `fulfilled` and `res.ok` has to be checked separately. - **Reaching for `allSettled()` where fail-fast is wanted.** If the first failure makes the rest of the work pointless, `Promise.all()` finishes sooner and saves resources.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.