Skip to content

Latest commit

 

History

History
118 lines (96 loc) · 3.7 KB

timeout.md

File metadata and controls

118 lines (96 loc) · 3.7 KB

Rx.Observable.prototype.timeout(dueTime, [other], [scheduler])

Returns the source observable sequence or the other observable sequence if dueTime elapses.

Arguments

  1. dueTime (Date | Number): Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) when a timeout occurs.
  2. [other] (Observable | Promise | string): Observable sequence or Promise to return in case of a timeout. If a string is specified, then an error will be thrown with the given error message. If not specified, a timeout error throwing sequence will be used.
  3. [scheduler=Rx.Observable.timeout] (Scheduler): Scheduler to run the timeout timers on. If not specified, the timeout scheduler is used.

Returns

(Observable): An observable sequence with time interval information on values.

Example

/* With no other */
var source = Rx.Observable
    .return(42)
    .delay(5000)
    .timeout(200);

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Error: Error: Timeout

/* With message */
var source = Rx.Observable
    .return(42)
    .delay(5000)
    .timeout(200, 'Timeout has occurred.');

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Error: Error: Timeout has occurred.

/* With an observable */
var source = Rx.Observable
  .return(42)
  .delay(5000)
  .timeout(200, Rx.Observable.empty());

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Completed

/* With a Promise */
var source = Rx.Observable
  .return(42)
  .delay(5000)
  .timeout(200, Promise.resolve(42));

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Next: 42
// => Completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: