Signature
tsSignature
export function race<const B extends BehaviorRecord>( behaviors: B, options?: { concurrency?: number },): Behavior<RecordInput<B>, RaceOutput<B>, RaceError<B> | EmptyRaceError, RecordContext<B>>;Imports
tsImport
import { race } from "@/lib/flow/race";import { race } from "@/lib/flow";Type Parameters
BBehavior record type.
Parameters
options{ concurrency?: number }
Optional concurrency limit.
Returns
A behavior producing a keyed success or keyed failure.
Return type
Behavior<RecordInput<B>, RaceOutput<B>, RaceError<B> | EmptyRaceError, RecordContext<B>>Details
On success, the returned value includes the winning key and value. On failure, the returned error
includes the failing key and error. Remaining active children are aborted.
Examples
tsExample
const fastestProfile = race({ primary: loadFromPrimary, replica: loadFromReplica,});Related Symbols
Behavior
Executable Flow workflow unit.
type
BehaviorRecord
Object map of named behaviors for `all`, `allSettled`, and `race`.
type
EmptyRaceError
Domain error returned when `race` is called with an empty behavior record.
type
RaceOutput
Keyed success value returned by `race`.
type
RecordContext
Intersects the custom context types of every behavior in a record.
type
RecordInput
Intersects the input types of every behavior in a record.
type
Source
tsflow/race.ts:42-53
export function race<const B extends BehaviorRecord>( behaviors: B, options?: { concurrency?: number },): Behavior<RecordInput<B>, RaceOutput<B>, RaceError<B> | EmptyRaceError, RecordContext<B>> { return async (input, context) => { if (context.signal.aborted) { return resultFromSignal(context.signal); }
return runRace(behaviors, input, context, options?.concurrency); };}