{"id":"async.ts","dependencies":[{"name":"/home/phoenix/Desktop/Projects/CargoDB/package.json","includedInParent":true,"mtime":1588969379438}],"generated":{"js":"\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n    return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n    function verb(n) { return function (v) { return step([n, v]); }; }\n    function step(op) {\n        if (f) throw new TypeError(\"Generator is already executing.\");\n        while (_) try {\n            if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\n            if (y = 0, t) op = [op[0] & 2, t.value];\n            switch (op[0]) {\n                case 0: case 1: t = op; break;\n                case 4: _.label++; return { value: op[1], done: false };\n                case 5: _.label++; y = op[1]; op = [0]; continue;\n                case 7: op = _.ops.pop(); _.trys.pop(); continue;\n                default:\n                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n                    if (t[2]) _.ops.pop();\n                    _.trys.pop(); continue;\n            }\n            op = body.call(thisArg, _);\n        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n    }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\n// Async base for extending \n// classes of an async behavior\nvar AsyncNature = /** @class */ (function () {\n    function AsyncNature(context) {\n        this.queue = [];\n        this.busy = false;\n        this.context = context !== null && context !== void 0 ? context : this;\n    }\n    // Run until all of\n    // of the operations\n    // are finished\n    AsyncNature.prototype.asyncLoop = function () {\n        return __awaiter(this, void 0, void 0, function () {\n            var _a, method, args, callback;\n            var _b;\n            return __generator(this, function (_c) {\n                // If there is what to iter\n                // get yourself to work\n                if (this.queue.length)\n                    this.busy = true;\n                // Loop'n'run all the ops in queue\n                while (this.busy) {\n                    // If done - headphones off and tada\n                    if (!this.queue.length) {\n                        this.busy = false;\n                    }\n                    // If stil something to do\n                    // roll up your sleeves\n                    else {\n                        _a = this.queue[0], method = _a.method, args = _a.args, callback = _a.callback;\n                        callback((_b = this.context)[method].apply(_b, args));\n                        this.queue.shift();\n                    }\n                }\n                return [2 /*return*/];\n            });\n        });\n    };\n    // Add operation and\n    // trigger the loop\n    AsyncNature.prototype.async = function (action, args) {\n        var _this = this;\n        return new Promise(function (res) {\n            // Add a cargo operation to queue\n            _this.queue.push({\n                args: args,\n                method: action,\n                callback: function () {\n                    var val = [];\n                    for (var _i = 0; _i < arguments.length; _i++) {\n                        val[_i] = arguments[_i];\n                    }\n                    res.apply(void 0, val);\n                }\n            });\n            // Trigger loop\n            if (!_this.busy) {\n                _this.asyncLoop();\n            }\n        });\n    };\n    return AsyncNature;\n}());\nexports.default = AsyncNature;\n"},"sourceMaps":{"js":{"version":3,"file":"async.js","sourceRoot":"","sources":["async.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,4BAA4B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GAAG,EAAC;gBAAC,CAAC;aACnC,CAAC,CAAA;YACF,eAAe;YACf,IAAI,CAAC,KAAI,CAAC,IAAI,EAAE;gBACZ,KAAI,CAAC,SAAS,EAAE,CAAA;aACnB;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAEL,kBAAC;AAAD,CAAC,AApDD,IAoDC","sourcesContent":["// It's a virtual representation\n// of a cargo operation method\ninterface CargoOperation {\n    args: Array<any>\n    method: string\n    callback: Function\n}\n\n// Async base for extending \n// classes of an async behavior\n\nexport default class AsyncNature {\n\n    private busy: boolean\n    private queue: Array<CargoOperation>\n\n    constructor(context: Object) {\n        this.queue = []\n        this.busy = false\n        this.context = context ?? this\n    }\n\n    // Run until all of\n    // of the operations\n    // are finished\n    private async asyncLoop() {\n        // If there is what to iter\n        // get yourself to work\n        if (this.queue.length) \n            this.busy = true\n        // Loop'n'run all the ops in queue\n        while (this.busy) {\n            // If done - headphones off and tada\n            if (!this.queue.length) {\n                this.busy = false\n            }\n            // If stil something to do\n            // roll up your sleeves\n            else {\n                const {method, args, callback} = this.queue[0]\n                callback(this.context[method](...args))\n                this.queue.shift()\n            }\n        }\n    }\n\n    // Add operation and\n    // trigger the loop\n    private async(action: string, args: Array<any>) {\n        return new Promise(res => {\n            // Add a cargo operation to queue\n            this.queue.push( <CargoOperation> {\n                args: args,\n                method: action,\n                callback(...val) { res(...val) }\n            })\n            // Trigger loop\n            if (!this.busy) {\n                this.asyncLoop()\n            }\n        })\n    }\n\n}\n"]}},"error":null,"hash":"85ce51c664907b8daabe806f844af9c4","cacheData":{"env":{}}}