merge and concat difference

Rxjs the merge and concat difference:

1, the same point:

A plurality of inputs are observable observable objects into an output object, by subscribing to obtain the input value of the objective wipe pop-up object;

 concat as long as there is an input error can observe objects that can be observed behind the input object can not eject its value, namely subscription termination; there is competition merge, there is an input error occurred observable objects will terminate the subscription.

2, different points:

merge in parallel, synchronization occurs, there is competition; is the concat series, the order of input values, the first observation target may be a pop-up completely, then start the second pop-up observation object may be sequentially output.

3, in fact, equivalent to the concat concurrent merge operator parameter to 1, i.e., concat (inputObv1, inputObv2, inputObv3, ....) === merge (inputObv1, inputObv2, inputObv3, ...., 1 )

  

. 1 const = O1 new new Observable <String> (Observer => {
 2        Timer (200 is) .subscribe (() => {
 . 3          observer.next ( '2S' );
 . 4          observer.error ( 'a first error input considerable rub given target, subsequent substantial wiping objects terminating subscribers' );
 . 5          observer.complete ();
 . 6        });
 . 7      });
 . 8    
. 9      const O2 = new new Observable <String> (Observer => {
 10        Timer (1000) .subscribe ( () => {
 . 11          observer.next ( 'lS' );
 12 is          observer.complete ();
 13 is       });
14     });
15     
16     concat(o1, o2).subscribe({
17       next(value) {
18         console.log('value: ', value);
19       },
20       error(reason) {
21         console.log('reason:', reason);
22       },
23       complete() {
24         console.log('complete');
25       }
26     });
27     
28     merge(o1, o2, 1).subscribe({
29       next(value) {
30         console.log('value: ', value);
31       },
32       error(reason) {
33         console.log('reason:', reason);
34       },
35       complete() {
36         console.log('complete');
37       }
38     });
39   }

 

Guess you like

Origin www.cnblogs.com/szy-du/p/11204274.html