all files / TypeScript.NET/source/System/Tasks/ defer.js

60.56% Statements 43/71
28.57% Branches 10/35
70.59% Functions 12/17
64.06% Lines 41/64
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                              16× 16× 16× 16×   16× 16× 16× 16× 16×       16× 16×                                                 16×            
/*!
 * @author electricessence / https://github.com/electricessence/
 * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
 */
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
(function (factory) {
    Eif (typeof module === 'object' && typeof module.exports === 'object') {
        var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
    }
    else if (typeof define === 'function' && define.amd) {
        define(["require", "exports"], factory);
    }
})(function (require, exports) {
    "use strict";
    var DeferBase = (function () {
        function DeferBase() {
        }
        DeferBase.prototype.dispose = function () {
            this.cancel();
        };
        return DeferBase;
    }());
    var Defer = (function (_super) {
        __extends(Defer, _super);
        function Defer(task, delay) {
            _super.call(this);
            Eif (!(delay > 0))
                delay = 0;
            this._id = setTimeout(Defer.handler, delay, task, this);
        }
        Defer.prototype.cancel = function () {
            var id = this._id;
            Eif (id) {
                clearTimeout(id);
                this._id = null;
                return true;
            }
            return false;
        };
        Defer.handler = function (task, d) {
            d.cancel();
            task();
        };
        return Defer;
    }(DeferBase));
    var DeferInterval = (function (_super) {
        __extends(DeferInterval, _super);
        function DeferInterval(task, interval, _remaining) {
            if (_remaining === void 0) { _remaining = Infinity; }
            _super.call(this);
            this._remaining = _remaining;
            if (interval === null || interval === void (0))
                throw "'interval' must be a valid number.";
            if (interval < 0)
                throw "'interval' cannot be negative.";
            this._id = setInterval(DeferInterval.handler, interval, task, this);
        }
        DeferInterval.prototype.cancel = function () {
            var id = this._id;
            if (id) {
                clearInterval(id);
                this._id = null;
                return true;
            }
            return false;
        };
        DeferInterval.handler = function (task, d) {
            if (!(--d._remaining))
                d.cancel();
            task();
        };
        return DeferInterval;
    }(DeferBase));
    function defer(task, delay) {
        return new Defer(task, delay);
    }
    exports.defer = defer;
    function interval(task, interval, count) {
        if (count === void 0) { count = Infinity; }
        return new DeferInterval(task, interval, count);
    }
    exports.interval = interval;
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.default = defer;
});
//# sourceMappingURL=defer.js.map