Skip to content

Latest commit

 

History

History
79 lines (64 loc) · 2.64 KB

delay.md

File metadata and controls

79 lines (64 loc) · 2.64 KB

Rx.Observable.prototype.delay(dueTime, [scheduler])

Time shifts the observable sequence by dueTime. The relative time intervals between the values are preserved.

Arguments

  1. dueTime (Date | Number): Absolute (specified as a Date object) or relative time (specified as an integer denoting milliseconds) by which to shift the observable sequence.
  2. [scheduler=Rx.Scheduler.timeout] (Scheduler): Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.

Returns

(Observable): Time-shifted sequence.

Example

/* Using an absolute time to delay by a second */
var source = Rx.Observable.range(0, 3)
    .delay(new Date(Date.now() + 1000));

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

// => Next: 0
// => Next: 1
// => Next: 2
// => Completed

/* Using an relatove time to delay by a second */
var source = Rx.Observable.range(0, 3)
    .delay(1000);

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

// => Next: 0
// => Next: 1
// => Next: 2
// => Completed

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: