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manager@1.1.1/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/async-task-manager@1.1.1/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\nvar __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nexports.__esModule = true;\nvar retryCounter = Symbol('retryCounter');\n// #region Task Queues\nvar TaskQueue = /** @class */ (function () {\n    function TaskQueue(toleration) {\n        var _this = this;\n        if (toleration === void 0) { toleration = 3; }\n        this.queue = [];\n        this.errorStack = []; // errors occured while processing\n        this._abortFlag = false; // is abort\n        this._doneFlag = false; // has done\n        this._handleFlag = false; // is handlering\n        this.total = 0;\n        this.succeed = 0;\n        this.failed = 0;\n        this.executed = 0;\n        this.toleration = 0;\n        this.__resolve = null;\n        this.__reject = null;\n        /**\n         * Add a task to the queue\n         * @param {TaskCapsule|function} task Task to be executed\n         */\n        this.add = function (task) {\n            task[retryCounter] = 0;\n            _this.queue.push(task);\n        };\n        this.__prepareToBegin = function () {\n            if (!_this._handleFlag) {\n                _this._abortFlag = false;\n                _this._doneFlag = false;\n                _this._handleFlag = true;\n                _this.total = _this.queue.length;\n                _this.succeed = 0;\n                _this.failed = 0;\n                _this.executed = 0;\n                _this.errorStack = [];\n                return true;\n            }\n            return false;\n        };\n        this.__execAmountChange = function (num) {\n            _this.executed += num;\n            if (_this.executed <= 0 && _this.queue.length === 0) {\n                _this.__finish();\n            }\n        };\n        this.__finish = function () {\n            _this._handleFlag = false;\n            _this._doneFlag = true;\n            var flag = _this.failed === 0;\n            if (flag) {\n                _this.__resolve();\n            }\n            else {\n                _this.__reject(_this.errorStack);\n            }\n        };\n        this.toleration = toleration;\n    }\n    TaskQueue.prototype.__consumeValid = function () {\n        if (this._doneFlag) {\n            if (this.executed > 0) {\n                console.warn('Called consume after the tasks were handled.');\n            }\n            return false;\n        }\n        else if (this._abortFlag) {\n            this.__finish();\n            return false;\n        }\n        else if (this.queue.length === 0) {\n            return false;\n        }\n        else {\n            return true;\n        }\n    };\n    TaskQueue.prototype.abort = function () {\n        this._abortFlag = true;\n    };\n    return TaskQueue;\n}());\nvar ParallelQueue = /** @class */ (function (_super) {\n    __extends(ParallelQueue, _super);\n    function ParallelQueue(_a) {\n        var _b = _a.limit, limit = _b === void 0 ? 5 : _b, _c = _a.span, span = _c === void 0 ? 300 : _c, toleration = _a.toleration;\n        var _this = _super.call(this, toleration) || this;\n        _this.__start = function () {\n            if (_this.__consumeValid()) {\n                if (_this.executed < _this.limitation && _this.queue.length > 0) {\n                    var task_1 = _this.queue.shift();\n                    _this.__execAmountChange(1);\n                    task_1().then(function () {\n                        // exec success\n                        _this.succeed += 1;\n                        _this.__execAmountChange(-1);\n                    }, function (err) {\n                        if (task_1[retryCounter] >= _this.toleration) {\n                            // retried many times still failed\n                            _this.failed += 1;\n                            _this.errorStack.push(err);\n                        }\n                        else {\n                            // failed but retry it\n                            task_1[retryCounter] += 1;\n                            _this.queue.unshift(task_1);\n                        }\n                        _this.__execAmountChange(-1);\n                    });\n                }\n                if (_this.timespan > 0) {\n                    setTimeout(_this.__start, _this.timespan);\n                }\n                else {\n                    _this.__start();\n                }\n            }\n        };\n        _this.limitation = limit;\n        _this.timespan = span;\n        return _this;\n    }\n    ParallelQueue.prototype.consume = function () {\n        var _this = this;\n        return new Promise(function (resolve, reject) {\n            _this.__resolve = resolve;\n            _this.__reject = reject;\n            if (_this.__prepareToBegin()) {\n                if (_this.queue.length > 0) {\n                    for (var _i = 0; _i < _this.limitation; _i += 1) {\n                        _this.__start();\n                    }\n                }\n                else {\n                    _this.__execAmountChange(0);\n                }\n            }\n            else {\n                _this.__reject(new Error('Unable to consume'));\n            }\n        });\n    };\n    return ParallelQueue;\n}(TaskQueue));\nexports.ParallelQueue = ParallelQueue;\nvar SerialQueue = /** @class */ (function (_super) {\n    __extends(SerialQueue, _super);\n    function SerialQueue(_a) {\n        var _b = _a.abortAfterFail, abortAfterFail = _b === void 0 ? false : _b, toleration = _a.toleration;\n        var _this = _super.call(this, toleration) || this;\n        _this.abortAfterFail = abortAfterFail;\n        return _this;\n    }\n    SerialQueue.prototype.__start = function () {\n        var _this = this;\n        if (this.__consumeValid()) {\n            this.__execAmountChange(1);\n            var task_2 = this.queue.shift();\n            task_2().then(function () {\n                _this.succeed += 1;\n                _this.__execAmountChange(-1);\n                _this.__start();\n            }, function (err) {\n                if (task_2[retryCounter] >= _this.toleration) {\n                    // retried many times still failed\n                    _this.failed += 1;\n                    _this.errorStack.push(err);\n                    if (_this.abortAfterFail) {\n                        _this.__finish();\n                        return false;\n                    }\n                }\n                else {\n                    // failed but retry it\n                    task_2[retryCounter] += 1;\n                    _this.queue.unshift(task_2);\n                }\n                _this.__execAmountChange(-1);\n                _this.__start();\n            });\n        }\n    };\n    SerialQueue.prototype.consume = function () {\n        var _this = this;\n        return new Promise(function (resolve, reject) {\n            _this.__resolve = resolve;\n            _this.__reject = reject;\n            if (_this.__prepareToBegin()) {\n                if (_this.queue.length > 0) {\n                    _this.__start();\n                }\n                else {\n                    _this.__execAmountChange(0);\n                }\n            }\n            else {\n                _this.__reject(new Error('Unable to consume'));\n            }\n        });\n    };\n    SerialQueue.prototype.abort = function () {\n        this._abortFlag = true;\n    };\n    return SerialQueue;\n}(TaskQueue));\nexports.SerialQueue = SerialQueue;\n"]}