4d351ea8ec6e57c9f9d228652e8c169daa8d84b457bf69604095aebcdf2351d5.json 4.9 KB

1
  1. {"ast":null,"code":"var Pool = /** @class */function () {\n function Pool(runTask, limit) {\n this.runTask = runTask;\n this.limit = limit;\n this.aborted = false;\n this.queue = [];\n this.processing = [];\n }\n Pool.prototype.enqueue = function (task) {\n var _this = this;\n return new Promise(function (resolve, reject) {\n _this.queue.push({\n task: task,\n resolve: resolve,\n reject: reject\n });\n _this.check();\n });\n };\n Pool.prototype.run = function (item) {\n var _this = this;\n this.queue = this.queue.filter(function (v) {\n return v !== item;\n });\n this.processing.push(item);\n this.runTask(item.task).then(function () {\n _this.processing = _this.processing.filter(function (v) {\n return v !== item;\n });\n item.resolve();\n _this.check();\n }, function (err) {\n return item.reject(err);\n });\n };\n Pool.prototype.check = function () {\n var _this = this;\n if (this.aborted) return;\n var processingNum = this.processing.length;\n var availableNum = this.limit - processingNum;\n this.queue.slice(0, availableNum).forEach(function (item) {\n _this.run(item);\n });\n };\n Pool.prototype.abort = function () {\n this.queue = [];\n this.aborted = true;\n };\n return Pool;\n}();\nexport { Pool };","map":{"version":3,"names":["Pool","runTask","limit","aborted","queue","processing","prototype","enqueue","task","_this","Promise","resolve","reject","push","check","run","item","filter","v","then","err","processingNum","length","availableNum","slice","forEach","abort"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/qiniu-js/esm/utils/pool.js"],"sourcesContent":["var Pool = /** @class */ (function () {\n function Pool(runTask, limit) {\n this.runTask = runTask;\n this.limit = limit;\n this.aborted = false;\n this.queue = [];\n this.processing = [];\n }\n Pool.prototype.enqueue = function (task) {\n var _this = this;\n return new Promise(function (resolve, reject) {\n _this.queue.push({\n task: task,\n resolve: resolve,\n reject: reject\n });\n _this.check();\n });\n };\n Pool.prototype.run = function (item) {\n var _this = this;\n this.queue = this.queue.filter(function (v) { return v !== item; });\n this.processing.push(item);\n this.runTask(item.task).then(function () {\n _this.processing = _this.processing.filter(function (v) { return v !== item; });\n item.resolve();\n _this.check();\n }, function (err) { return item.reject(err); });\n };\n Pool.prototype.check = function () {\n var _this = this;\n if (this.aborted)\n return;\n var processingNum = this.processing.length;\n var availableNum = this.limit - processingNum;\n this.queue.slice(0, availableNum).forEach(function (item) {\n _this.run(item);\n });\n };\n Pool.prototype.abort = function () {\n this.queue = [];\n this.aborted = true;\n };\n return Pool;\n}());\nexport { Pool };\n"],"mappings":"AAAA,IAAIA,IAAI,GAAG,aAAe,YAAY;EAClC,SAASA,IAAIA,CAACC,OAAO,EAAEC,KAAK,EAAE;IAC1B,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,OAAO,GAAG,KAAK;IACpB,IAAI,CAACC,KAAK,GAAG,EAAE;IACf,IAAI,CAACC,UAAU,GAAG,EAAE;EACxB;EACAL,IAAI,CAACM,SAAS,CAACC,OAAO,GAAG,UAAUC,IAAI,EAAE;IACrC,IAAIC,KAAK,GAAG,IAAI;IAChB,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;MAC1CH,KAAK,CAACL,KAAK,CAACS,IAAI,CAAC;QACbL,IAAI,EAAEA,IAAI;QACVG,OAAO,EAAEA,OAAO;QAChBC,MAAM,EAAEA;MACZ,CAAC,CAAC;MACFH,KAAK,CAACK,KAAK,CAAC,CAAC;IACjB,CAAC,CAAC;EACN,CAAC;EACDd,IAAI,CAACM,SAAS,CAACS,GAAG,GAAG,UAAUC,IAAI,EAAE;IACjC,IAAIP,KAAK,GAAG,IAAI;IAChB,IAAI,CAACL,KAAK,GAAG,IAAI,CAACA,KAAK,CAACa,MAAM,CAAC,UAAUC,CAAC,EAAE;MAAE,OAAOA,CAAC,KAAKF,IAAI;IAAE,CAAC,CAAC;IACnE,IAAI,CAACX,UAAU,CAACQ,IAAI,CAACG,IAAI,CAAC;IAC1B,IAAI,CAACf,OAAO,CAACe,IAAI,CAACR,IAAI,CAAC,CAACW,IAAI,CAA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