race
The race operator picks the observable sequence that emits first. Once one of the input streams starts producing values, the others are immediately unsubscribed and disregarded.
The resulting stream mirrors the chosen input: it completes when that stream completes, errors if that stream errors, and never completes if the selected stream never completes.
Here’s how the operator behaves:
- Subscribes to every source observable
- Forwards values from whichever source emits first
- Cancels subscriptions to all remaining source observables
- Signals completion to the observer once the winning source finishes
- Propagates an error notification if the winning source throws
The diagram below illustrates race combining two streams, A and B, each with three items. Only the values from stream A appear in the output, because it starts emitting first.

Usage
This operator shines when multiple sources can supply the same data—for instance, servers distributed across different regions where network latency is unpredictable. You can broadcast a single request to several endpoints and use the response from whichever arrives first.
The example below uses race to fire multiple HTTP requests and cancel the slower ones:
const a = fromFetch('https://api.mocki.io/v1/0350b5d5');
const b = fromFetch('https://api.mocki.io/v1/ce5f60e2');
race(a, b).subscribe((response) => console.log(response));
