Reactive-Extensions/RxJS

View on GitHub
doc/api/core/operators/amb.md

Summary

Maintainability
Test Coverage
# This is RxJS v 4. [Find the latest version here](https://github.com/reactivex/rxjs)
### `Rx.Observable.amb(...args)` [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/linq/observable/amb.js "View in source")
 
Propagates the observable sequence or Promise that reacts first. "amb" stands for [ambiguous](http://blogs.msdn.com/b/jeffva/archive/2009/11/18/amb-materialize-and-dematerialize.aspx).
 
#### Arguments
1. `args` *(Array|arguments)*: Observable sources or Promises competing to react first either as an array or arguments.
 
#### Returns
*(`Observable`)*: An observable sequence that surfaces any of the given sequences, whichever reacted first.
 
#### Example
```js
/* 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
```
 
### Location
 
File:
- [`/src/core/linq/observable/amb.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/linq/observable/amb.js)
 
Dist:
- [`rx.all.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.all.js)
- [`rx.all.compat.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.all.compat.js)
- [`rx.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.js)
- [`rx.compat.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/dist/rx.compat.js)
 
Prerequisites:
- None
 
NPM Packages:
- [`rx`](https://www.npmjs.org/package/rx)
 
NuGet Packages:
- [`RxJS-Complete`](http://www.nuget.org/packages/RxJS-Complete/)
- [`RxJS-Main`](http://www.nuget.org/packages/RxJS-Main/)
 
Unit Tests:
- [`/tests/observable/amb.js`](https://github.com/Reactive-Extensions/RxJS/blob/master/tests/observable/amb.js)