Skip to content

Latest commit

 

History

History
93 lines (78 loc) · 2.97 KB

delaywithselector.md

File metadata and controls

93 lines (78 loc) · 2.97 KB

Rx.Observable.prototype.delayWithSelector([subscriptionDelay], delayDurationSelector)

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

Arguments

  1. [subscriptionDelay] (Observable): Sequence indicating the delay for the subscription to the source.
  2. delayDurationSelector (Function): Selector function to retrieve a sequence indicating the delay for each given element.

Returns

(Observable): Time-shifted sequence.

Example

/* With subscriptionDelay */
var source = Rx.Observable
    .range(0, 3)
    .delayWithSelector(
        Rx.Observable.timer(300),
        function (x) {
            return Rx.Observable.timer(x * 400);
        }
    )
    .timeInterval()
    .map(function (x) { return x.value + ':' + x.interval; });

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

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

/* Without subscriptionDelay */
var source = Rx.Observable
    .range(0, 3)
    .delayWithSelector(
        function (x) {
            return Rx.Observable.timer(x * 400);
        })
    .timeInterval()
    .map(function (x) { return x.value + ':' + x.interval; });

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

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

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: