使用选择器函数将指定的 Observable 序列合并为一个 Observable 序列,只有在(第一个)源 Observable 序列生成一个元素时才会调用该函数。
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/withLatestFrom/withLatestFrom.php
/* Have staggering intervals */
$source1 = \Rx\Observable::interval(140)
->map(function ($i) {
return 'First: ' . $i;
});
$source2 = \Rx\Observable::interval(50)
->map(function ($i) {
return 'Second: ' . $i;
});
$source3 = \Rx\Observable::interval(100)
->map(function ($i) {
return 'Third: ' . $i;
});
$source = $source1->withLatestFrom([$source2, $source3], function ($value1, $value2, $value3) {
return $value1 . ', ' . $value2 . ', ' . $value3;
})->take(4);
$source->subscribe($stdoutObserver);
Next value: First: 0, Second: 1, Third: 0
Next value: First: 1, Second: 4, Third: 1
Next value: First: 2, Second: 7, Third: 3
Next value: First: 3, Second: 10, Third: 4
Complete!