# all files / TypeScript.NET/source/System/Disposable/ dispose.js

66.25% Statements 53/80
45.83% Branches 22/48
75% Functions 9/12
67.11% Lines 51/76

    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

    1×
    1×
    1×

    1×
    1×
    4937×
    4937×
    4984×

    4937×

    1×
    1×
    1×
    1×

    1×
    1×

    1×
    1×
    25×

    1×
    1×
    1×
    1×

    1×

    1×
    245×
    245×

    245×

    1×
    1×
    5204×
    1438×

    1438×

    5204×

    1×
    4940×
    4940×
    4940×
    4940×
    4991×
    4991×
    32×
    4959×

    4959×
    4959×
    4959×
    4959×

    4959×

    4959×

    4940×

    1×
    1×

     /*!
     * @author electricessence / https://github.com/electricessence/
     * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
     */
    (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", "../Types"], factory);
        }
    })(function (require, exports) {
        "use strict";
        var Types_1 = require("../Types");
        function dispose() {
            var disposables = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                disposables[_i - 0] = arguments[_i];
            }
            disposeTheseInternal(disposables, false);
        }
        exports.dispose = dispose;
        var dispose;
        (function (dispose) {
            function deferred() {
                var disposables = [];
                for (var _i = 0; _i < arguments.length; _i++) {
                    disposables[_i - 0] = arguments[_i];
                }
                these.deferred(disposables);
            }
            dispose.deferred = deferred;
            function withoutException() {
                var disposables = [];
                for (var _i = 0; _i < arguments.length; _i++) {
                    disposables[_i - 0] = arguments[_i];
                }
                return disposeTheseInternal(disposables, true);
            }
            dispose.withoutException = withoutException;
            function these(disposables, trapExceptions) {
                return disposables && disposables.length
                    ? disposeTheseInternal(disposables.slice(), trapExceptions)
                    : null;
            }
            dispose.these = these;
            var these;
            (function (these) {
                function deferred(disposables, delay) {
                    if (delay === void 0) { delay = 0; }
                    if (disposables && disposables.length) {
                        if (!(delay >= 0))
                            delay = 0;
                        setTimeout(disposeTheseInternal, delay, disposables.slice(), true);
                    }
                }
                these.deferred = deferred;
            })(these = dispose.these || (dispose.these = {}));
        })(dispose = exports.dispose || (exports.dispose = {}));
        function using(disposable, closure) {
            try {
                return closure(disposable);
            }
            finally {
                disposeSingle(disposable, false);
            }
        }
        exports.using = using;
        function disposeSingle(disposable, trapExceptions) {
            if (disposable && Types_1.Type.of(disposable).member('dispose').isFunction) {
                Iif (trapExceptions) {
                    try {
                        disposable.dispose();
                    }
                    catch (ex) {
                        return ex;
                    }
                }
                else
                    disposable.dispose();
            }
            return null;
        }
        function disposeTheseInternal(disposables, trapExceptions, index) {
            Eif (index === void 0) { index = 0; }
            var exceptions;
            var len = disposables.length;
            for (; index < len; index++) {
                var next = disposables[index];
                if (!next)
                    continue;
                Iif (trapExceptions) {
                    var ex = disposeSingle(next, true);
                    if (ex) {
                        if (!exceptions)
                            exceptions = [];
                        exceptions.push(ex);
                    }
                }
                else {
                    var success = false;
                    try {
                        disposeSingle(next, false);
                        success = true;
                    }
                    finally {
                        Iif (!success && index + 1 < len) {
                            disposeTheseInternal(disposables, false, index + 1);
                        }
                    }
                    Iif (!success)
                        break;
                }
            }
            return exceptions;
        }
        Object.defineProperty(exports, "__esModule", { value: true });
        exports.default = dispose;
    });
    //# sourceMappingURL=dispose.js.map