Promise.all
All must fulfill, or the whole operation rejects.
Promise composition lets you coordinate multiple async operations: all, allSettled, race and any.
const [profile, settings] = await Promise.all([ loadProfile(), loadSettings() ]);
Async JavaScript
Promise.all waits for all promises to fulfill, but rejects as soon as one rejects. Use it when every result is required.
Promise.allSettled waits for every promise and gives each outcome. Use it when partial success is useful.
Promise.race and Promise.any are specialized tools for first result patterns, timeouts and fallback strategies.
All must fulfill, or the whole operation rejects.
Waits for all outcomes.
Settles with the first promise to settle.
Fulfills with the first fulfillment.
Examples
const results = await Promise.allSettled(tasks); const fulfilled = results.filter(result => result.status === "fulfilled");
const widgets = await Promise.all(widgetRequests); // One failure prevents every widget from rendering.
Code patterns
These examples are the async patterns you will reuse: timers, promises, composition, await, fetch and cancellation.
Fail fast if any required task fails.
const results = await Promise.all([loadA(), loadB()]);
Keep successful results even when some fail.
const results = await Promise.allSettled([loadA(), loadB()]);
Race work against a timeout promise.
const result = await Promise.race([loadData(), timeout(3000)]);
Use any for fallback sources.
const data = await Promise.any([fromCache(), fromNetwork()]);
Rules that matter
Async JavaScript is easier when every operation has clear pending, success, failure and cancellation behavior.
Every promise must succeed.
Partial content can still be useful.
The losing operation may still continue unless cancelled.
It ignores rejections until all reject.
Promise.any can reject with AggregateError.
all and allSettled keep the input order, not completion order.
Production thinking
Async applications rarely load one thing. Composition is how you coordinate many things without chaos.
Partial loading should communicate which sections succeeded and which failed.
Production code should choose composition based on product behavior, not habit.
If page sections load independently, failures should not leave the whole page empty.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
If you can explain when the code runs, how it fails and what happens if it becomes irrelevant, you understand the async model.