Course contentsShow
← JavaScript
Lesson 1317 of 2,72329. PromisesFree lesson

allSettled for Independent Operations

Use allSettled when executing multiple independent tasks that shouldn't block each other.

allSettled for Independent Operations

What you'll learn: When to choose Promise.allSettled() for tasks that should complete independently without blocking each other.

The Core Idea

When you have multiple asynchronous operations that are independent — meaning one task's failure shouldn't prevent the others from completing — Promise.allSettled() is your tool. Unlike Promise.all(), which short-circuits on the first rejection, allSettled() always waits for every promise to finish, regardless of success or failure.

When to Use allSettled for Independence

Think of independent operations like running separate diagnostics on a car: checking tire pressure, scanning the engine, and testing the battery. If the battery test fails, you still want results from the tire and engine checks. You need the complete picture, not an early exit.

Common scenarios:

  • Fetching data from multiple sources where some APIs might fail
  • Batch processing where you want to know which items succeeded and which failed
  • Parallel validations where you need all validation results
  • Logging/analytics where failure of one tracker shouldn't block others
const operations = [
  fetch('/api/user'),
  fetch('/api/settings'),
  fetch('/api/notifications')
];

Promise.allSettled(operations)
  .then(results => {
    results.forEach((result, index) => {
      if (result.status === 'fulfilled') {
        console.log(`Operation ${index} succeeded:`, result.value);
      } else {
        console.log(`Operation ${index} failed:`, result.reason);
      }
    });
  });

Each operation runs independently. If /api/settings fails, you still get results from user and notifications.

Key Takeaway: Use Promise.allSettled() when operations are independent and you need all outcomes, not just success cases — it guarantees completion of all tasks without early termination.