Amb
given two or more source Observables, emit all of the items from only the first of these Observables to emit an item or notification
When you pass a number of source Observables to Amb, it will pass through the emissions and notifications of exactly one of these Observables: the first one that sends a notification to Amb, either by emitting an item or sending an onError
or onCompleted
notification. Amb will ignore and discard the emissions and notifications of all of the other source Observables.
See Also
Language-Specific Information
RxGroovy amb ambWith

RxGroovy implements this operator as amb
. It takes up to nine Observables as individual parameters, or a single Iterable of Observables. There is also an instance version of the operator, ambWith
, so that, for example, instead of writing Observable.amb(o1,o2)
you could also write o1.ambWith(o2)
for the same effect.
This operator does not by default operate on any particular Scheduler.
- Javadoc:
amb(Iterable)
- Javadoc:
amb(Observable,Observable)
(there are also versions that take up to nine Observable parameters) - Javadoc:
ambWith(Observable)
RxJava 1․x amb ambWith

RxJava 1.x implements this operator as amb
. It takes up to nine Observables as individual parameters, or a single Iterable of Observables. There is also an instance version of the operator, ambWith
, so that, for example, instead of writing Observable.amb(o1,o2)
you could also write o1.ambWith(o2)
for the same effect.
This operator does not by default operate on any particular Scheduler.
- Javadoc:
amb(Iterable)
- Javadoc:
amb(Observable,Observable)
(there are also versions that take up to nine Observable parameters) - Javadoc:
ambWith(Observable)
RxJava 2․x amb ambArray ambWith

RxJava 2.x implements this operator as amb
. It takes an Iterable of Observables as its parameter. You can also use ambArray
to pass an array of Observables. There is also an instance version of the operator, ambWith
, so that, for example, instead of writing Observable.ambArray([o1,o2])
you could also write o1.ambWith(o2)
for the same effect.
This operator does not by default operate on any particular Scheduler.
- Javadoc:
amb(Iterable)
- Javadoc:
ambArray(Iterable)
- Javadoc:
ambWith(Observable)
RxJS amb

RxJS implements this operator as amb
. It takes a variable number of parameters, which may be either Observables or Promises (or combinations of the two).
Sample Code
/* Using Observable sequences */ var source = Rx.Observable.amb( Rx.Observable.timer(500).select(function () { return 'foo'; }), Rx.Observable.timer(200).select(function () { return 'bar'; }) ); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: bar Completed
/* Using Promises and Observables */ var source = Rx.Observable.amb( RSVP.Promise.resolve('foo') Rx.Observable.timer(200).select(function () { return 'bar'; }) ); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: foo Completed
RxPHP race
RxPHP implements this operator as race
.
Propagates the observable sequence that reacts first. Also known as 'amb'.
Sample Code
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/race/race.php $source = Rx\Observable::race( [ Rx\Observable::timer(500)->map(function () { return 'foo'; }), Rx\Observable::timer(200)->map(function () { return 'bar'; }) ] ); $source->subscribe($stdoutObserver);
Next value: bar Complete!
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/amb.html