skip to content

combineLatest

 

Creates Observable from multiple Observables.
Resulting stream will emit a combined value of all latest emissions of input streams

NOTE: take a look at rxjs/autorun package that let's you easily combine multiple streams emissions in any form

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


const a$ = timer(0, 10).pipe(
    take(5)
  );

const b$ = timer(0, 4).pipe(
    take(7)
  );

const result$ = combineLatest(a$, b$);

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

0msa$startcomplete00 11 22 33 44 b$startcomplete00 11 22 33 44 55 66 combineLatest(a$, b$)startcomplete[0,0][0,0] [0,1][0,1] [0,2][0,2] [1,2][1,2] [1,3][1,3] [1,4][1,4] [2,4][2,4] [2,5][2,5] [2,6][2,6] [3,6][3,6] [4,6][4,6]