Rx.Observable.amb(...args)
Ⓢ
Propagates the observable sequence or Promise that reacts first. "amb" stands for ambiguous.
args
(Array|arguments): Observable sources or Promises competing to react first either as an array or arguments.
(Observable
): An observable sequence that surfaces any of the given sequences, whichever reacted first.
/* 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
File:
Dist:
Prerequisites:
- None
NPM Packages:
NuGet Packages:
Unit Tests: