Wednesday, November 28, 2018

Difference Between MergeMap and ConcatMap


Concatmap is sequential do not subscribe another if another is in progress.

Mergemap is parallel, subscribe all inner observable at home nce and enit values as soon as one comlete.


Example :

const series1$ = of('a', 'b');

const series2$ = of('x', 'y');

const result$ = concat(series1$, series2$);

result$.subscribe(console.log);

Output : a ,b, x, y

Example Merge

const series1$ = interval(1000).pipe(map(val => val*10));

const series2$ = interval(1000).pipe(map(val => val*100));

const result$ = merge(series1$, series2$);


result$.subscribe(console.log);

Output 

0
0
10
100
20
200
30
300
https://blog.angular-university.io/rxjs-higher-order-mapping/

No comments:

Followers

Link