Promise.allSettled: Examples and Use Cases in JavaScript
Promise.allSettled waits for all promises, even failures. Here are practical examples.
Promise.allSettled: Examples and Use Cases in JavaScript
Promise.allSettled waits for all promises to settle, even if some reject. Here are practical examples.
Basic Usage
const results = await Promise.allSettled([ fetchA(), fetchB(), fetchC(), ]); results.forEach((r) => { if (r.status === "fulfilled") { console.log("Success:", r.value); } else { console.error("Failed:", r.reason); } }); `` Each result has a `status` (`"fulfilled"` or `"rejected"`). Fulfilled results have `value`; rejected results have `reason`. ### Partial Success ```js const results = await Promise.allSettled([ fetchUser(1), fetchUser(2), fetchUser(3), // this one fails ]); const successful = results.filter((r) => r.status === "fulfilled").map((r) => r.value); const failed = results.filter((r) => r.status === "rejected").map((r) => r.reason); console.log("Successful:", successful); console.log("Failed:", failed); `` You get all successful results and all failures. No fast fail. ### Fetching from Multiple Sources (Best Effort) ```js const results = await Promise.allSettled([ fetchFromCache(), fetchFromCDN(), fetchFromOrigin(), ]); const firstSuccess = results.find((r) => r.status === "fulfilled"); if (firstSuccess) { render(firstSuccess.value); } `` Try multiple sources and use the first successful one (or all successful ones). ### Difference from Promise.all ```js // Promise.all: fast fail (if any rejects, the whole thing rejects) const [a, b, c] = await Promise.all([fetchA(), fetchB(), fetchC()]); // Promise.allSettled: wait for all (never rejects) const results = await Promise.allSettled([fetchA(), fetchB(), fetchC()]); `` ### The Takeaway `Promise.allSettled` waits for all promises, even if some reject. Each result has `{ status, value/reason }`. Use for partial success (some results even if some fail), best-effort fetching from multiple sources, and when you never want the whole thing to reject. Never fast-fails.
It waits for all promises to settle (fulfilled or rejected) and returns an array of { status, value/reason } objects. It never rejects. Use it for partial success when you want all results regardless of failures.
Promise.all rejects if any promise rejects (fast fail) and returns an array of values. Promise.allSettled waits for all promises, never rejects, and returns an array of { status, value/reason } objects.
No. Promise.allSettled always fulfills. It returns an array of result objects, each with a status of 'fulfilled' or 'rejected'. This is why it is useful for partial success scenarios.
{ status: 'fulfilled', value: ... } for fulfilled promises, or { status: 'rejected', reason: ... } for rejected promises. Check r.status to determine which, then access r.value or r.reason.
When you want all results even if some promises reject (partial success). For example, fetching from multiple sources and using whichever succeeds, or batch operations where some failures are acceptable.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

