Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 2.36 KB

switchfirst.md

File metadata and controls

70 lines (51 loc) · 2.36 KB

Rx.Observable.prototype.switchFirst()

Receives an Observable of Observables and propagates the first Observable exclusively until it completes before it begins subscribes to the next Observable. Observables that come before the current Observable completes will be dropped and will not propagate.

This operator is similar to concatAll() except that it will not hold onto Observables that come in before the current one is finished completed.

Returns

(Observable): An Observable sequence that is the result of concatenating non-overlapping items emitted by an Observable of Observables.

Example

//Generate an event every 100 milliseconds
var source = Rx.Observable.generateWithRelativeTime(
   0,
   function(x) {return x < 5; },
   function(x) {return x + 1; },
   function(x) {return x; },
   function(x) {return 100; })
  .map(function(value) {
    //Observable takes 150 milliseconds to complete
    return Rx.Observable.timer(150).map(value);
  });


source.exclusive().subscribe(
   function (x) {
    console.log("Next %d", x);
   }, function(e) {
    console.log("Error %s", e);
   }, function() {
    console.log("Completed");
   });


// Next 0
// Next 2
// Next 4
// Completed

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests:

  • None