For each item from only the first of the given observables deliver from the new observable that is returned, on the specified scheduler.
More...
For each item from only the first of the given observables deliver from the new observable that is returned, on the specified scheduler.
There are 2 variants of the operator:
- The source observable emits nested observables, one of the nested observables is selected.
- The source observable and the arguments v0...vn are used to provide the observables to select from.
- Template Parameters
-
Coordination | the type of the scheduler (optional). |
Value0 | ... (optional). |
ValueN | types of source observables (optional). |
- Parameters
-
cn | the scheduler to synchronize sources from different contexts (optional). |
v0 | ... (optional). |
vn | source observables (optional). |
- Returns
- Observable that emits the same sequence as whichever of the source observables first emitted an item or sent a termination notification.
If scheduler is omitted, identity_current_thread is used.
- Sample Code\n
printf("[thread %s] Start task\n", get_pid().c_str());
printf("[thread %s] Timer1 fired\n", get_pid().c_str());
return 1;
});
printf("[thread %s] Timer2 fired\n", get_pid().c_str());
return 2;
});
printf("[thread %s] Timer3 fired\n", get_pid().c_str());
return 3;
});
values.
[](int v){printf("[thread %s] OnNext: %d\n", get_pid().c_str(), 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 139846724261632] Timer3 fired
[thread 139846724261632] OnNext: 3
[thread 139846724261632] OnCompleted
[thread 139846724265792] Finish task
auto values = base.
amb();
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
auto values = o1.
amb(o2, o3);
values.
[](int v){printf("OnNext: %d\n", v);},
[](){printf("OnCompleted\n");});
printf("[thread %s] Start task\n", get_pid().c_str());
printf("[thread %s] Timer1 fired\n", get_pid().c_str());
return 1;
});
printf("[thread %s] Timer2 fired\n", get_pid().c_str());
return 2;
});
printf("[thread %s] Timer3 fired\n", get_pid().c_str());
return 3;
});
values.
[](int v){printf("[thread %s] OnNext: %d\n", get_pid().c_str(), 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 139846724261632] Timer3 fired
[thread 139846724261632] OnNext: 3
[thread 139846724261632] OnCompleted
[thread 139846724265792] Finish task