W3cubDocs

/RxJS

race

function stable

Returns an Observable that mirrors the first source Observable to emit an item.

race<T>(...observables: ObservableInput<any>[]): Observable<T>

Parameters

observables

Type: ObservableInput[].

Returns

Observable<T>: an Observable that mirrors the output of the first Observable to emit an item.

Description

Example

Subscribes to the observable that was the first to start emitting.

import { race, interval } from 'rxjs';
import { mapTo } from 'rxjs/operators';

const obs1 = interval(1000).pipe(mapTo('fast one'));
const obs2 = interval(3000).pipe(mapTo('medium one'));
const obs3 = interval(5000).pipe(mapTo('slow one'));

race(obs3, obs1, obs2)
.subscribe(
  winner => console.log(winner)
);

// result:
// a series of 'fast one'

Overloads

race(arg: [ObservableInput<A>]): Observable<A>

Parameters

arg

Type: [ObservableInput].

Returns

Observable<A>

race(arg: [ObservableInput<A>, ObservableInput<B>]): Observable<A | B>

Parameters

arg

Type: [ObservableInput, ObservableInput].

Returns

Observable<A | B>

race(arg: [ObservableInput<A>, ObservableInput<B>, ObservableInput<C>]): Observable<A | B | C>

Parameters

arg

Type: [ObservableInput, ObservableInput, ObservableInput].

Returns

Observable<A | B | C>

race(arg: [ObservableInput<A>, ObservableInput<B>, ObservableInput<C>, ObservableInput<D>]): Observable<A | B | C | D>

Parameters

arg

Type: [ObservableInput, ObservableInput, ObservableInput, ObservableInput].

Returns

Observable<A | B | C | D>

race(arg: [ObservableInput<A>, ObservableInput<B>, ObservableInput<C>, ObservableInput<D>, ObservableInput<E>]): Observable<A | B | C | D | E>

Parameters

arg

Type: [ObservableInput, ObservableInput, ObservableInput, ObservableInput, ObservableInput].

Returns

Observable<A | B | C | D | E>

race(arg: ObservableInput<T>[]): Observable<T>

Parameters

arg

Type: ObservableInput[].

Returns

Observable<T>

race(arg: ObservableInput<any>[]): Observable<{ }>

Parameters

arg

Type: ObservableInput[].

Returns

Observable<{ }>

race(a: ObservableInput<A>): Observable<A>

Parameters

a

Type: ObservableInput.

Returns

Observable<A>

race(a: ObservableInput<A>, b: ObservableInput<B>): Observable<A | B>

Parameters

a

Type: ObservableInput.

b

Type: ObservableInput.

Returns

Observable<A | B>

race(a: ObservableInput<A>, b: ObservableInput<B>, c: ObservableInput<C>): Observable<A | B | C>

Parameters

a

Type: ObservableInput.

b

Type: ObservableInput.

c

Type: ObservableInput.

Returns

Observable<A | B | C>

race(a: ObservableInput<A>, b: ObservableInput<B>, c: ObservableInput<C>, d: ObservableInput<D>): Observable<A | B | C | D>

Parameters

a

Type: ObservableInput.

b

Type: ObservableInput.

c

Type: ObservableInput.

d

Type: ObservableInput.

Returns

Observable<A | B | C | D>

race(a: ObservableInput<A>, b: ObservableInput<B>, c: ObservableInput<C>, d: ObservableInput<D>, e: ObservableInput<E>): Observable<A | B | C | D | E>

Parameters

a

Type: ObservableInput.

b

Type: ObservableInput.

c

Type: ObservableInput.

d

Type: ObservableInput.

e

Type: ObservableInput.

Returns

Observable<A | B | C | D | E>

race(observables: ObservableInput<T>[]): Observable<T>

Parameters

observables

Type: ObservableInput[].

Returns

Observable<T>

race(observables: ObservableInput<any>[]): Observable<{ }>

Parameters

observables

Type: ObservableInput[].

Returns

Observable<{ }>

race(...observables: ObservableInput<T>[]): Observable<T>

Parameters

observables

Type: ObservableInput[].

Returns

Observable<T>

race(...observables: ObservableInput<any>[]): Observable<{ }>

Parameters

observables

Type: ObservableInput[].

Returns

Observable<{ }>

© 2015–2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/function/race