The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Combination operator: merge

Combination operator: merge

3:57
In the category of combination operators, concat executes Observables sequentially, while merge executes them in parallel. This lesson will teach you how the merge operator is an OR-style combination operator that blends two or more Observables together.
Watch this lesson now
Avatar
egghead.io

In the category of combination operators, concat executes Observables sequentially, while merge executes them in parallel. This lesson will teach you how the merge operator is an OR-style combination operator that blends two or more Observables together.

Avatar
Klemen

Wouldn't the marble diagram for the example given look like this?

--0-01--21-3--24-(3|)

The (24) wouldn't happen synchronously, just very closely together.

Avatar
Andre

Hi Klemen. Yes that is to some extent correct, but it depends on the underlying scheduler. Schedulers are a concept we don't cover in this course, but in a nutshell they allow you to choose what is "time" and how to run things with time. Here, the Observable.interval() would schedule emissions with a setInterval, and that's why 2 and 4 would not be emitted synchronously. However, if we used the VirtualTimeScheduler, it would just simulate a setInterval, and essentially then it is able to accomplish emissions of 2 and 4 at the "same time" (under its own concept of time).

What matters here is that each character in the ascii marble diagram stands for one "time unit", and what the original diagram meant is that 2 and 4 occur "in the same time unit". --24- isn't correct either because 4 does not occur "one time unit" (in our case, 100ms) ahead of 2.

In reply to Klemen
Avatar
Klemen

Ah, OK, that makes sense. Thank you!

In reply to Andre
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?