Ch. 1 · JavaScript

JavaScript Promise Combinators and Failure Modes

JavaScript Promise Combinators and Failure Modes. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readintermediateupdated Oct 3, 2026

All requires every fulfillment; allSettled records all outcomes; race follows first settlement; any follows first fulfillment. Match the choice to acceptable partial failure.

Step-by-step walkthrough

Step 1: Describe acceptable partial failure

Do all tasks need to succeed, can individual failures be shown, or is one successful result enough? These product rules select the combinator. Do not choose Promise.all merely because several requests happen at once.

Step 2: Distinguish settlement from fulfillment

Race follows the first settled promise, including a rejection. Any follows the first fulfillment and rejects only when all candidates reject. AllSettled gives one status per input. All rejects when an input rejects while leaving already-started work running.

Step 3: Own the losing work

A selected winner does not automatically cancel other requests. Coordinate supported abort signals and decide whether losers should finish for caching or stop to save resources. Set a deadline for operations whose useful lifetime is bounded.

Worked scenario

Independent dashboard widgets can use allSettled. Redundant read endpoints can use any to choose the first successful response.

const bad = Promise.reject(new Error('unavailable'));
const good = Promise.resolve('usable');
console.log(await Promise.any([bad, good])); // usable
const outcomes = await Promise.allSettled([bad, good]);
console.log(outcomes.map(item => item.status));
// ['rejected', 'fulfilled']
JavaScript

Walk through the example

Both promises already exist before the combinators observe them. Any accepts the fulfilled value despite another rejection. AllSettled retains both outcomes in input order. The example is about result selection; real network operations still need deadlines, cancellation and an appropriate policy for retrying failures.

Common mistake

A timeout race leaves losing work running unless it is explicitly cancelled.

Verify the behavior

Resolve two controlled operations in different orders and reject the fastest one. Check that race and any produce different outcomes. Test empty inputs: all and allSettled fulfill with empty arrays, any rejects, and race stays pending.

Interview exercise

What if every redundant endpoint fails?

Answer and reasoning

Promise.any rejects with AggregateError. Report the failure and release outstanding work where cancellation is supported.

Follow-up discussion

Can a timeout race stop fetch? It can stop waiting for its result, but fetch needs a signal to request cancellation. When is allSettled appropriate? When failures are independent and callers need a complete per-operation report rather than one combined failure.

Continue learning

Compare the scenario with the JavaScript interview questions and test your understanding with the JavaScript MCQs. For terminology and implementation details, consult the reference material.

More in JavaScript

read ✓JavaScript · mid

JavaScript Date and Timezone Pitfalls

Parse and format dates without timezone surprises: zero-based months, date-only versus date-time parsing, and why UTC storage avoids drift.

~3 min readread →
esc