Learn JavaScript
❯ async.promise_combinators

Promise.all, race, allSettled & any in JavaScript

$concept

Combinators coordinate multiple promises: all (all fulfill in order, or first rejection wins), allSettled (every outcome as {status, value/reason} — never rejects), race (first settlement of any kind wins), any (first fulfillment wins, AggregateError only if all reject). Non-promise values pass through as already-fulfilled.

Choose by failure semantics: all for must-all-succeed batches, allSettled for best-effort fan-out, race for timeouts (Promise.race([work, delayReject])), any for first-success redundancy (mirrors, CDNs). Empty-iterable edges (all([]) fulfills [], race([]) pends forever) deserve explicit handling.

$how it works
1

all: everything or fail

Promise.all([...]) fulfills [v1, v2] in order — one rejection rejects the whole, siblings keep running unobserved.

2

allSettled: every outcome

Never rejects — [{status: "fulfilled", value}, {status: "rejected", reason}] per input for best-effort batches.

3

race: first settlement

First to settle (fulfill OR reject) wins — timeout patterns race work against delayReject.

4

any: first success

First fulfillment wins; total failure rejects AggregateError carrying all reasons in .errors.

$example
let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2);
Promise.all([p1, p2]).then((v) => console.log(v));
Promise.race([p1, p2]).then((v) => console.log(v));
Output
[ 1, 2 ]
1
1all collects both fulfillments in input order — [1, 2].
2race takes the first settlement — p1's 1 (both immediate, first listed wins ties deterministically here).
3Coordination primitives composing independent promises.
$use cases
Parallel fan-out with all plus awaited join
Timeouts racing work against delayReject
Best-effort batches via allSettled with per-outcome handling
Redundant sources with any (mirrors, fallbacks)

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.