Promise.allSettled() is a promise concurrency method introduced in ES2020 that is used to run multiple asynchronous operations in parallel. Unlike Promise.all(), which “short-circuits” and fails immediately if any single promise rejects, Promise.allSettled() waits for every single promise to finish, regardless of whether they succeeded or failed.

It returns a single promise that resolves to an array of objects, where each object describes the outcome of each promise in the original iterable.


1. Core Logic and Syntax

The method is designed for scenarios where you need to know the result of all tasks, such as cleaning up resources, updating a UI with partial data, or logging which specific API calls failed while still processing the ones that worked.

JavaScript

Promise.allSettled(iterable);

The Output Format

The resulting array contains objects with the following properties:

  • For Fulfilled Promises: { status: "fulfilled", value: result }

  • For Rejected Promises: { status: "rejected", reason: error }


2. Practical Example: Bulk API Requests

Imagine you are sending a batch of email notifications. If one email address is invalid and the promise rejects, you still want the other emails to be sent and you want a report of which ones failed.

JavaScript

const emails = [
  sendEmail('user1@example.com'),
  sendEmail('invalid-email'),
  sendEmail('user3@example.com')
];

Promise.allSettled(emails)
  .then((results) => {
    results.forEach((result, index) => {
      if (result.status === 'fulfilled') {
        console.log(`Email ${index} sent successfully:`, result.value);
      } else {
        console.error(`Email ${index} failed:`, result.reason);
      }
    });
  });

3. Advanced Pattern: Filtering Results

Because allSettled() gives you an array of statuses, it is very easy to separate the “wins” from the “losses” using standard array methods.

JavaScript

const requests = [fetch('/api/1'), fetch('/api/2'), fetch('/api/3')];

const results = await Promise.allSettled(requests);

// Extract only the successful responses
const successfulResponses = results
  .filter(res => res.status === 'fulfilled')
  .map(res => res.value);

// Extract only the errors for logging
const errors = results
  .filter(res => res.status === 'rejected')
  .map(res => res.reason);

4. Why was it added to JavaScript?

Before Promise.allSettled(), developers had to manually wrap every promise in a .catch() block to prevent Promise.all() from failing the entire batch:

JavaScript

// The "Old Way" (Manual workaround)
Promise.all(promises.map(p => p.catch(e => e)));

Promise.allSettled() standardizes this behavior, providing a clean, built-in way to handle non-dependent parallel tasks without the risk of a single error crashing your entire asynchronous flow.

5. Advanced Use Case: Partial Success Management

Promise.allSettled() is extremely powerful for database operations or file uploads where you want to provide the user with a summary of what worked and what didn’t.

JavaScript

async function uploadFiles(files) {
  const uploadPromises = files.map(file => uploadFileToS3(file));
  
  const outcomes = await Promise.allSettled(uploadPromises);
  
  const successful = outcomes.filter(o => o.status === 'fulfilled').length;
  const failed = outcomes.filter(o => o.status === 'rejected').length;
  
  console.log(`Upload complete: ${successful} succeeded, ${failed} failed.`);
}

Categorized in:

Javascript,