Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / src/public-api / race

Function: race()

race<T>(...streams): Atom<T[number]>

Defined in: projects/libraries/streamix/src/lib/factories/race.ts:22

Returns an atom that races multiple input sources. It emits values from the first source that produces a value, then cancels all other sources.

This operator is useful for scenarios where you only need the result from the fastest of several asynchronous operations. For example, fetching data from multiple servers and only taking the result from the one that responds first.

Once the winning source completes, the output atom also completes. If the winning source emits an error, the output atom will emit that error.

Type Parameters

T

T extends readonly unknown[] = any[]

A tuple type representing the combined values from the sources.

Parameters

streams

...{ [K in string | number | symbol]: PipeInput<T[K<K>]> }

Atoms, streams, or values (including promises) to race against each other.

Returns

Atom<T[number]>

A new atom that emits values from the first source to produce a value.

Released under the GNU AGPL v3 or later.