For each item from the first observable select the latest value from all the observables to emit from the new observable that is returned.
More...
For each item from the first observable select the latest value from all the observables to emit from the new observable that is returned.
- Template Parameters
-
AN | types of scheduler (optional), aggregate function (optional), and source observables |
- Parameters
-
an | scheduler (optional), aggregation function (optional), and source observables |
- Returns
- Observable that emits items that are the result of combining the items emitted by the source observables.
If scheduler is omitted, identity_current_thread is used.
If aggregation function is omitted, the resulting observable returns tuples of emitted items.
- Sample Code\n
Neither scheduler nor aggregation function are present:
auto values = o1.with_latest_from(o2, o3);
values.
[](std::tuple<int, int, int> v){printf("OnNext: %d, %d, %d\n", std::get<0>(v), std::get<1>(v), std::get<2>(v));},
[](){printf("OnCompleted\n");});
OnNext: 2, 1, 1
OnNext: 3, 2, 1
OnNext: 4, 2, 2
OnNext: 5, 3, 2
OnNext: 6, 4, 2
OnCompleted
Only scheduler is present:
printf("[thread %s] Start task\n", get_pid().c_str());
printf("[thread %s] Source1 OnNext: %d\n", get_pid().c_str(), v);
return v;
});
printf("[thread %s] Source2 OnNext: %d\n", get_pid().c_str(), v);
return v;
});
printf("[thread %s] Source3 OnNext: %d\n", get_pid().c_str(), v);
return v;
});
auto values = o1.with_latest_from(thr, o2, o3);
values.
[](std::tuple<int, int, int> v){printf("[thread %s] OnNext: %d, %d, %d\n", get_pid().c_str(), std::get<0>(v), std::get<1>(v), std::get<2>(v));},
[](){printf("[thread %s] OnCompleted\n", get_pid().c_str());});
printf("[thread %s] Finish task\n", get_pid().c_str());
[thread 139846724265792] Start task
[thread 139846724265792] Source1 OnNext: 1
[thread 139846724265792] Source2 OnNext: 1
[thread 139846724265792] Source3 OnNext: 1
[thread 139846724265792] Source1 OnNext: 2
[thread 139846483965696] OnNext: 2, 1, 1
[thread 139846724265792] Source2 OnNext: 2
[thread 139846724265792] Source1 OnNext: 3
[thread 139846483965696] OnNext: 3, 2, 1
[thread 139846724265792] Source3 OnNext: 2
[thread 139846724265792] Source1 OnNext: 4
[thread 139846724265792] Source2 OnNext: 3
[thread 139846483965696] OnNext: 4, 2, 2
[thread 139846724265792] Source1 OnNext: 5
[thread 139846483965696] OnNext: 5, 3, 2
[thread 139846724265792] Source2 OnNext: 4
[thread 139846724265792] Source1 OnNext: 6
[thread 139846724265792] Source3 OnNext: 3
[thread 139846483965696] OnNext: 6, 4, 2
[thread 139846483965696] OnCompleted
[thread 139846724265792] Finish task
Only aggregation function is present:
auto values = o1.with_latest_from(
[](int v1, int v2, int v3) {
return 100 * v1 + 10 * v2 + v3;
},
o2, o3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 211
OnNext: 321
OnNext: 422
OnNext: 532
OnNext: 642
OnCompleted
Both scheduler and aggregation function are present:
auto values = o1.with_latest_from(
[](int v1, int v2, int v3) {
return 100 * v1 + 10 * v2 + v3;
},
o2, o3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
OnNext: 211
OnNext: 321
OnNext: 422
OnNext: 532
OnNext: 642
OnCompleted