# Code coverage report for RxJS/dist/cjs/operators/delay.js

## Statements: 87.5% (70 / 80) Branches: 64.71% (22 / 34) Functions: 93.33% (14 / 15) Lines: 88.89% (64 / 72) Ignored: none

All files » RxJS/dist/cjs/operators/ » delay.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123

    1
    1

    3

    1

    16

    1

    1

    1

    1

    1

    1

    1
    4

    4

    1
    1
    4

    4
    4

    1
    4

    1

    1
    1

    1
    4

    4
    4
    4
    4
    4
    4

    1
    5
    5
    5
    5
    5
    8

    5
    1
    1

    4

    1
    4

    4
    4
    4
    4

    1

    1
    4

    4
    4
    4

    1
    4
    4

    1

    1
    8

    8
    8

    1'use strict';

    exports.__esModule = true;
    exports['default'] = delay;

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

    function _inherits(subClass, superClass) { Iif (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

    var _Subscriber2 = require('../Subscriber');

    var _Subscriber3 = _interopRequireDefault(_Subscriber2);

    var _Notification = require('../Notification');

    var _Notification2 = _interopRequireDefault(_Notification);

    var _schedulersImmediate = require('../schedulers/immediate');

    var _schedulersImmediate2 = _interopRequireDefault(_schedulersImmediate);

    function delay(delay) {
        var scheduler = arguments.length <= 1 || arguments[1] === undefined ? _schedulersImmediate2['default'] : arguments[1];

        return this.lift(new DelayOperator(delay, scheduler));
    }

    var DelayOperator = (function () {
        function DelayOperator(delay, scheduler) {
            _classCallCheck(this, DelayOperator);

            this.delay = delay;
            this.scheduler = scheduler;
        }

        DelayOperator.prototype.call = function call(subscriber) {
            return new DelaySubscriber(subscriber, this.delay, this.scheduler);
        };

        return DelayOperator;
    })();

    var DelaySubscriber = (function (_Subscriber) {
        _inherits(DelaySubscriber, _Subscriber);

        function DelaySubscriber(destination, delay, scheduler) {
            _classCallCheck(this, DelaySubscriber);

            _Subscriber.call(this, destination);
            this.queue = [];
            this.active = false;
            this.errored = false;
            this.delay = delay;
            this.scheduler = scheduler;
        }

        DelaySubscriber.dispatch = function dispatch(state) {
            var source = state.source;
            var queue = source.queue;
            var scheduler = state.scheduler;
            var destination = state.destination;
            while (queue.length > 0 && queue[0].time - scheduler.now() <= 0) {
                queue.shift().notification.observe(destination);
            }
            if (queue.length > 0) {
                var _delay = Math.max(0, queue[0].time - scheduler.now());
                this.schedule(state, _delay);
            } else {
                source.active = false;
            }
        };

        DelaySubscriber.prototype._next = function _next(x) {
            Iif (this.errored) {
                return;
            }
            var scheduler = this.scheduler;
            this.queue.push(new DelayMessage(scheduler.now() + this.delay, _Notification2['default'].createNext(x)));
            Eif (this.active === false) {
                this._schedule(scheduler);
            }
        };

        DelaySubscriber.prototype._error = function _error(e) {
            var scheduler = this.scheduler;
            this.errored = true;
            this.queue = [new DelayMessage(scheduler.now() + this.delay, _Notification2['default'].createError(e))];
            if (this.active === false) {
                this._schedule(scheduler);
            }
        };

        DelaySubscriber.prototype._complete = function _complete() {
            Iif (this.errored) {
                return;
            }
            var scheduler = this.scheduler;
            this.queue.push(new DelayMessage(scheduler.now() + this.delay, _Notification2['default'].createComplete()));
            Iif (this.active === false) {
                this._schedule(scheduler);
            }
        };

        DelaySubscriber.prototype._schedule = function _schedule(scheduler) {
            this.active = true;
            this.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
                source: this, destination: this.destination, scheduler: scheduler
            }));
        };

        return DelaySubscriber;
    })(_Subscriber3['default']);

    var DelayMessage = function DelayMessage(time, notification) {
        _classCallCheck(this, DelayMessage);

        this.time = time;
        this.notification = notification;
    };

    module.exports = exports['default'];