Why Promise.allSettled Beats Promise.all for Robust Async Handling
Promise.allSettled enhances JavaScript concurrency by waiting for every promise to settle—whether fulfilled or rejected—so developers can retrieve all results and handle errors more flexibly, unlike Promise.all which aborts on the first rejection.
In the world of JavaScript asynchronous programming, Promise.all has long been the primary tool for concurrency control, but it has a clear limitation: if any task fails, the entire process stops and the results of other tasks cannot be obtained. A more powerful API is now available for developers to handle concurrent tasks.
Advantages of Promise.allSettled
Promise.allSettled is a concurrency‑control API provided by JavaScript that lets you wait for all promises to complete (whether fulfilled or rejected) and obtain each promise's final status and result. Unlike Promise.all, Promise.allSettled does not short‑circuit on a single rejection; it continues waiting for all promises to finish.
Basic usage
Comparison with Promise.all
Promise.all rejects as soon as any promise is rejected, which may be desirable in some scenarios, but in many cases we want to obtain the results of all tasks even if some fail.
Practical application scenarios
Batch data processing
When you need to process a large number of independent data items and each processing step may fail, Promise.allSettled is the ideal choice.
API request aggregation
When you need to send requests to multiple endpoints and aggregate all results, Promise.allSettled ensures you obtain all available data even if some requests fail.
Concurrent task management
When you have multiple independent tasks that need to run in parallel and the success or failure of one should not affect the others, Promise.allSettled is a safer choice.
Other concurrency control APIs
Besides Promise.allSettled, JavaScript also provides other concurrency control APIs:
Promise.all : use when all promises must succeed.
Promise.race : use when you need the result of the fastest promise.
Promise.any : use when you need the first fulfilled promise.
Promise.allSettled gives JavaScript developers more powerful concurrency control. When handling multiple asynchronous tasks, it ensures you can retrieve the final state of every task, regardless of success or failure, making error handling and result processing more flexible and reliable.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JavaScript
Provides JavaScript enthusiasts with tutorials and experience sharing on web front‑end technologies, including JavaScript, Node.js, Deno, Vue.js, React, Angular, HTML5, CSS3, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
