The zip()
operator is similar to the ForkJoinObservable
that we implemented ourselves in Chapter 5, Testing RxPHP Code. The main difference is that it internally stores all emissions for each source Observable in a separate queue and then re-emits their values when all sources have a value at a specific index.
This will be understood better by looking at the following example:
// zip_01.php $obs1 = Observable::range(1, 7); $obs2 = Observable::fromArray(['a', 'b']); $obs3 = Observable::range(42, 5); $obs1->zip([$obs2, $obs3]) ->subscribe(new DebugSubject());
We have three source Observables where each of them emits a different number of items. Then the zip()
operator emits an array of values only when all the sources have emissions at the same index. So we know that DebugSubject
will receive only two items because the $obs2
Observable emits only two items.
In other words, the zip()
operator can't make the third emission because...