awaitRace()function
awaitRace(...promises: Promise<T>[]): Promise<T>
| Param | Type | |
|---|---|---|
promises | Promise<T>[] | The promises to race against each other. required |
| Return | |
|---|---|
Promise<T> | A promise that settles with the first input to settle. |
| Throws | |
|---|---|
unknown | The rejection reason of the first input to settle, if it rejects. |
Race promises like Promise.race() but silently swallow rejections from the losers.
- Returns a promise that settles with the first input to settle, exactly like
Promise.race(). - The losing inputs keep running (Promises cannot be cancelled), but their eventual rejection — if any — is silently absorbed instead of bubbling up as an unhandled rejection.
- Built for cancellation/timeout patterns, where the loser's eventual fate is genuinely uninteresting once another arm has settled. Do not use when both arms might surface meaningful errors that the caller should see.
Examples
await awaitRace(getDelay(300), awaitAbort(signal)); // delay or abort, no leaked ABORT rejection if delay wins