Skip to content

staggeredRace

staggeredRace<Candidate, Result>(candidates, attempt, options): Promise<Result>

Defined in: packages/async/src/race/staggered-race.ts:38

Try candidates in order, starting the next one when the previous has not succeeded within delayMs — or at once when it fails — and settle with the first success: RFC 8305 “Happy Eyeballs” connection racing, for any candidates.

Losing attempts are aborted through the signal passed to attempt. Starts at most candidates.length attempts; time is bounded by the slowest attempt only when all fail.

Candidate

Result

readonly Candidate[]

What to try, in order of preference.

MaybeAsyncCallable<[Candidate, AbortSignal], Result>

Tries one candidate; must honour signal.

StaggeredRaceOptions<Result>

The stagger delay, and how to dispose of late successes.

Promise<Result>

The first successful result.

The only attempt’s error when there is one candidate, an AggregateError of every attempt’s error otherwise, or signal’s reason.