angular wait all subscriptions

Solutions on MaxInterview for angular wait all subscriptions by the best coders in the world

showing results for - "angular wait all subscriptions"
Davide
15 Apr 2017
1// Concat 
2let first = Observable.timer(10,500).map(r => {
3  return {source:1,value:r};
4}).take(4);
5let second = Observable.timer(10,500).map(r => {
6  return {source:2,value:r};
7}).take(4);
8first.concat(second).subscribe(res => this.concatStream.push(res));
9// This will merge the two but you will receive the first observable result before the second:
10// 0 1 2 3 0 1 2 3
11
12// Merge
13let first = Observable.timer(10,500).map(r => {
14  return {source:1,value:r};
15}).take(4);
16let second = Observable.timer(10,500).map(r => {
17  return {source:2,value:r};
18}).take(4);
19first.merge(second).subscribe(res => this.mergeStream.push(res));
20
21// You will get:
22// 0 0 1 1 2 2 3 3
23
24// Fork Join
25let first = Observable.of({source:1,value:1});
26let second = Observable.of({source:2,value:1});
27Observable.forkJoin(first,second).subscribe((res:Array) => this.forkJoinStream = res);
28
29// FlatMap
30let first = Observable.of(10);
31first.flatMap((operand1) => {
32  return Observable.of(operand1 + 10);
33})
34.subscribe(res => this.flatMappedStreams = {msg: '10 + 10 = ' + res});
35