util-helpers 5.7.8 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/util-helpers.js +55 -1
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/ConcurrencyController.js +54 -0
- package/esm/VERSION.js +1 -1
- package/esm/index.js +1 -0
- package/lib/ConcurrencyController.js +56 -0
- package/lib/VERSION.js +1 -1
- package/lib/index.js +2 -0
- package/package.json +1 -1
- package/types/ConcurrencyController.d.ts +45 -2
- package/types/index.d.ts +1 -0
package/dist/util-helpers.js
CHANGED
|
@@ -2202,7 +2202,7 @@
|
|
|
2202
2202
|
return internalFindTreeSelect(tree, predicate, childrenField);
|
|
2203
2203
|
}
|
|
2204
2204
|
|
|
2205
|
-
var VERSION = "5.
|
|
2205
|
+
var VERSION = "5.8.0";
|
|
2206
2206
|
|
|
2207
2207
|
/**
|
|
2208
2208
|
* 事件触发器,支持浏览器端和 node 端。
|
|
@@ -3228,7 +3228,61 @@
|
|
|
3228
3228
|
return AsyncMemo;
|
|
3229
3229
|
}());
|
|
3230
3230
|
|
|
3231
|
+
var ConcurrencyController = (function () {
|
|
3232
|
+
function ConcurrencyController(maxConcurrency) {
|
|
3233
|
+
if (maxConcurrency === void 0) { maxConcurrency = 2; }
|
|
3234
|
+
this.maxConcurrency = Math.max(maxConcurrency, 1);
|
|
3235
|
+
this.runningCount = 0;
|
|
3236
|
+
this.queue = [];
|
|
3237
|
+
this.isPaused = false;
|
|
3238
|
+
}
|
|
3239
|
+
ConcurrencyController.prototype.add = function (task) {
|
|
3240
|
+
var _this = this;
|
|
3241
|
+
return new Promise(function (resolve, reject) {
|
|
3242
|
+
_this.queue.push({ task: task, resolve: resolve, reject: reject });
|
|
3243
|
+
_this._run();
|
|
3244
|
+
});
|
|
3245
|
+
};
|
|
3246
|
+
ConcurrencyController.prototype._run = function () {
|
|
3247
|
+
var _this = this;
|
|
3248
|
+
if (this.isPaused)
|
|
3249
|
+
return;
|
|
3250
|
+
while (this.runningCount < this.maxConcurrency && this.queue.length > 0) {
|
|
3251
|
+
var _a = this.queue.shift(), task = _a.task, resolve = _a.resolve, reject = _a.reject;
|
|
3252
|
+
this.runningCount++;
|
|
3253
|
+
task()
|
|
3254
|
+
.then(resolve)
|
|
3255
|
+
.catch(reject)
|
|
3256
|
+
.finally(function () {
|
|
3257
|
+
_this.runningCount--;
|
|
3258
|
+
_this._run();
|
|
3259
|
+
});
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
ConcurrencyController.prototype.getStatus = function () {
|
|
3263
|
+
return {
|
|
3264
|
+
running: this.runningCount,
|
|
3265
|
+
waiting: this.queue.length,
|
|
3266
|
+
maxConcurrency: this.maxConcurrency,
|
|
3267
|
+
paused: this.isPaused
|
|
3268
|
+
};
|
|
3269
|
+
};
|
|
3270
|
+
ConcurrencyController.prototype.setMaxConcurrency = function (maxConcurrency) {
|
|
3271
|
+
this.maxConcurrency = Math.max(maxConcurrency, 1);
|
|
3272
|
+
this._run();
|
|
3273
|
+
};
|
|
3274
|
+
ConcurrencyController.prototype.pause = function () {
|
|
3275
|
+
this.isPaused = true;
|
|
3276
|
+
};
|
|
3277
|
+
ConcurrencyController.prototype.resume = function () {
|
|
3278
|
+
this.isPaused = false;
|
|
3279
|
+
this._run();
|
|
3280
|
+
};
|
|
3281
|
+
return ConcurrencyController;
|
|
3282
|
+
}());
|
|
3283
|
+
|
|
3231
3284
|
exports.AsyncMemo = AsyncMemo;
|
|
3285
|
+
exports.ConcurrencyController = ConcurrencyController;
|
|
3232
3286
|
exports.VERSION = VERSION;
|
|
3233
3287
|
exports.ajax = ajax;
|
|
3234
3288
|
exports.bytesToSize = bytesToSize;
|