race

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

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

Parameters

observables

Type: (Observable[] | Observable)[].

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(a: Observable<A>, b: Observable<B>): Observable<A> | Observable<B>

Parameters

a

Type: Observable.

b

Type: Observable.

Returns

Observable<A> | Observable<B>

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

Parameters

a

Type: Observable.

b

Type: Observable.

c

Type: Observable.

Returns

Observable<A> | Observable<B> | Observable<C>

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

Parameters

a

Type: Observable.

b

Type: Observable.

c

Type: Observable.

d

Type: Observable.

Returns

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

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

Parameters

a

Type: Observable.

b

Type: Observable.

c

Type: Observable.

d

Type: Observable.

e

Type: Observable.

Returns

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

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

Parameters

observables

Type: Observable[].

Returns

Observable<T>

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

Parameters

observables

Type: Observable[].

Returns

Observable<{ }>

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

Parameters

observables

Type: Observable[].

Returns

Observable<T>

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

Parameters

observables

Type: Observable[].

Returns

Observable<{ }>