DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. Promise.allSettled, Promise.any, and Promise.race Explained
XLinkedInReddit
MediumFrontend Engineering

Promise.allSettled, Promise.any, and Promise.race Explained

D
DevPrep Team
February 10, 2026·2 min read·0
Table of Contents
  • Promise.all — All or Nothing
  • Promise.allSettled — Get Everything
  • Promise.race — First to Finish
  • Promise.any — First Success
  • Decision Matrix
  • Production Pattern: Resilient Fetching

Beyond Promise.all, JavaScript offers three more combinators that solve specific concurrency problems.

Promise.all — All or Nothing

// Rejects immediately if ANY promise rejects
const results = await Promise.all([
  fetch("/api/users"),
  fetch("/api/posts"),
  fetch("/api/comments")
]);
// If /api/posts fails, you get NOTHING

Promise.allSettled — Get Everything

const results = await Promise.allSettled([
  fetch("/api/users"),
  fetch("/api/posts"),    // Even if this fails...
  fetch("/api/comments")
]);
// results = [
//   { status: "fulfilled", value: Response },
//   { status: "rejected", reason: Error },
//   { status: "fulfilled", value: Response }
// ]

// Filter successes
const successful = results
  .filter(r => r.status === "fulfilled")
  .map(r => r.value);

Promise.race — First to Finish

// Returns the first promise to settle (fulfill OR reject)
const result = await Promise.race([
  fetch("/api/data"),
  new Promise((_, reject) =>
    setTimeout(() => reject(new Error("Timeout")), 5000)
  )
]);
// Timeout pattern: either data arrives or 5s timeout

Promise.any — First Success

// Returns the first promise to FULFILL (ignores rejections)
const fastest = await Promise.any([
  fetch("https://cdn1.example.com/data"),
  fetch("https://cdn2.example.com/data"),
  fetch("https://cdn3.example.com/data")
]);
// Gets data from whichever CDN responds first
// Only rejects if ALL promises reject (AggregateError)

Decision Matrix

MethodUse WhenFails When
Promise.allNeed ALL results, fail fastAny rejects
Promise.allSettledWant all results regardlessNever rejects
Promise.raceNeed fastest responseFirst to settle rejects
Promise.anyNeed first successALL reject

Production Pattern: Resilient Fetching

async function resilientFetch(url, { timeout = 5000, retries = 3 } = {}) {
  for (let i = 0; i < retries; i++) {
    try {
      return await Promise.race([
        fetch(url),
        new Promise((_, reject) =>
          setTimeout(() => reject(new Error("Timeout")), timeout)
        )
      ]);
    } catch (err) {
      if (i === retries - 1) throw err;
      await new Promise(r => setTimeout(r, 1000 * Math.pow(2, i)));
    }
  }
}

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • Promise.all — All or Nothing
  • Promise.allSettled — Get Everything
  • Promise.race — First to Finish
  • Promise.any — First Success
  • Decision Matrix
  • Production Pattern: Resilient Fetching

Series

View all Frontend Engineering articles →

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.