janci
janci

Reputation: 489

The output from combineLatestAll() operator seems to be incorrect

I have this little peace of code:

      var s2 = of(6, 16, 26).pipe(map(v1=>of(5, 15, 25).pipe(map(v2=>[v2,v1]))), combineLatestAll());
      s2.subscribe(console.log)

It produces output below - I understand the third output generated (by the time the first stream starts the second one is finished - so it always starts with 25 I guess) but I don't understand why the first two outputs are generated.

[25, 6]
[25, 16]
[5, 26]

[25, 6]
[25, 16]
[15, 26]

[25, 6]
[25, 16]
[25, 26]

Upvotes: 0

Views: 168

Answers (1)

a better oliver
a better oliver

Reputation: 26828

This is a timeline of what happens:

O1 [5,6] [15,6] [25,6]

O2                      [5,16] [15,16] [25,16]        

O3                                             [5,26]  [15,26] [25,26]

CLA                              latest O1 ->  [25,6]  [25,6]  [25,6]                                              
                                 latest O2 ->  [25,16] [25,16] [25,16]
                                 latest O3 ->  [5,26]  [15,26] [25,26]

combineLatestAll subscribes to all observables. When you subscribe to a stream such as of(5, 15, 25) it completes before anything else can happen. So observable 1 completes, observable 2 completes and the values emitted by observable 3 are each combined with the latest values from O1 and O2.

Upvotes: 1

Related Questions