Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 2.32 KB

amb.md

File metadata and controls

76 lines (60 loc) · 2.32 KB

Rx.Observable.amb(...args)

Propagates the observable sequence or Promise that reacts first. "amb" stands for ambiguous.

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

/* 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:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests: