skip to content

race

 

Once received a value, error or completion event from any given stream, race will reproduce all events from that stream, while unsubscribing from other streams

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const { rxObserver } = require('api/v0.3');
const { timer, race } = require('rxjs');
const { mapTo, take } = require('rxjs/operators');


const a$ = timer(10).pipe(mapTo('a'));
const b$ = timer(5, 5).pipe(take(3));

const result$ = race([ a$, b$ ]);

a$.subscribe(rxObserver('a$'));
b$.subscribe(rxObserver('b$'));
result$.subscribe(rxObserver('race(a$, b$)'));

0msa$startcompleteaa b$startcomplete00 11 22 race(a$, b$)startcomplete00 11 22