Async JavaScript
Promise Combinators
Promise combinators coordinate multiple async operations.
all, allSettled, race, and any encode different success and failure strategies.Promise.allis all-or-fail-fastPromise.allSettledwaits for every outcomePromise.raceuses first settled resultPromise.anyuses first fulfillment- Combinators do not cancel the losers automatically
| Combinator | Fulfillment | Rejection | Good for |
|---|---|---|---|
| Promise.all | All fulfill | First rejection | Independent required work |
| Promise.allSettled | Always after all settle | Never from child rejection | Batch reports |
| Promise.race | First settled fulfills | First settled rejects | Timeouts / first response |
| Promise.any | First fulfillment | All reject | Fallback mirrors |
const results = await Promise.allSettled(urls.map(fetchJson))
const successes = []
const failures = []
for (const result of results) {
if (result.status === "fulfilled") successes.push(result.value)
else failures.push(result.reason)
}