Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
77 lines (61 loc) · 2.41 KB

amb.md

File metadata and controls

77 lines (61 loc) · 2.41 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: