Video summary
Promise APIs + Interview Questions 🔥 | S.02 Ep.05 - Namaste JavaScript | all, allSettled, race, any
Main summary
Key takeaways
Main ideas / lessons
- The video explains 4 important JavaScript Promise combinator APIs for running multiple promises (often parallel API calls) and controlling behavior around success, failure, and timing.
- It emphasizes the “settle” terminology:
- A promise settles when it becomes either fulfilled/success or rejected/failure.
- Interviewers may confuse these terms, so the speaker recommends using “settled/settle” consistently.
The 4 Promise APIs (contracts + behavior)
1) Promise.all(iterableOfPromises)
Purpose: Run many promises in parallel; require all to succeed.
Input
- Takes an iterable (commonly an array) of promises.
Success case
- If all promises fulfill, it returns a single promise that fulfills to an array:
- Output array contains results in the same order as the input promises.
- Timing: completes in ~the time of the slowest promise.
Failure case
- If any one promise rejects,
Promise.all:- rejects immediately (fail-fast)
- uses the rejection reason/error from the first promise that rejects
- does not wait for remaining promises.
- Cancellation note: already-started promises can’t be cancelled (as described, JS doesn’t provide easy cancellation for promises).
Behavior intuition
- “All or none” / “fail fast”.
2) Promise.allSettled(iterableOfPromises)
Purpose: Run promises in parallel and get results for all, regardless of success/failure.
Input
- Takes an iterable (commonly an array) of promises.
Output format
- Always fulfills with an array of the same length as the input.
- Each element is an object like:
{ status: "fulfilled", value: <result> }or{ status: "rejected", reason: <error> }
Success/failure handling
- It waits for every promise to settle (fulfilled or rejected).
- No early failure; returns the combined settled results only after all complete.
Timing
- Takes ~the time of the slowest promise.
Behavior intuition
- “Safe option”: useful when you want to render partial data even if some calls fail.
3) Promise.race(iterableOfPromises)
Purpose: Return the result of the first promise to settle (fulfilled or rejected).
Input
- Takes an iterable (commonly an array) of promises.
Success/failure
- Whichever promise settles first wins:
- If the first settled promise fulfills → you get its value
- If the first settled promise rejects → the returned promise rejects with that error
- Does not wait for others.
Timing
- ~time of the earliest settlement.
Behavior intuition
- “Race”: first settled promise determines outcome (success or failure).
4) Promise.any(iterableOfPromises)
Purpose: Return the first successful fulfillment among promises; ignore failures until a success happens.
Input
- Takes an iterable (commonly an array) of promises.
Behavior
- Waits until one promise fulfills:
- On first success → returns that fulfilled value.
- If a promise rejects, it is ignored as long as another may still succeed.
If all promises fail
- After all have rejected, it rejects with an aggregate error:
- the aggregate error includes an array of all rejection errors.
Timing
- Completes as soon as the first success happens.
- If none succeed, it completes after the last rejection.
Behavior intuition
- “Success-seeking race”.
Practical code/demonstration methodology shown (high-level)
The speaker demonstrates each API by:
- Creating dummy promises using
setTimeoutto control resolve/reject timing. - Logging results to show:
- Output shape (
arrayvsvaluevsobject) - Timing differences (e.g., resolving at 1s/2s/3s)
- Fail-fast vs wait-all behavior
- Output shape (
- Teaching good practice:
- Use
.catch(...)to avoid “uncaught” promise errors in the demo.
- Use
Speakers / sources featured
- Speaker: The host/teacher of “Namaste JavaScript” (no personal name explicitly stated in the subtitles).
- Source: The video itself: “Promise APIs + Interview Questions 🔥 | S.02 Ep.05 - Namaste JavaScript | all, allSettled, race, any”.