Loading...
const res = await Promise.race([
fetch(primaryUrl),
fetch(mirrorUrl),
]);const res = await Promise.any([
fetch(primaryUrl),
fetch(mirrorUrl),
]);race() rejects if the fastest request fails; any() waits for the first request that succeeds.
Promise.race() for fallbacks and failing whenever the fastest source errors.AggregateError and missing the real causes.Promise.any() are read from error.errors, the array inside the AggregateError.Promise.any() is used for the first success; Promise.race() only when the first settled result, even a failure, is wanted.AbortController.Promise.any() fulfills with the first success and rejects only if all fail. Promise.race() settles with whichever promise settles first, success or failure.
Promise.any() do with an empty array?It rejects right away with an AggregateError whose errors array is empty.