UNPKG

@visactor/vtable

Version:

canvas table width high performance

30 lines (26 loc) 922 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.LimitPromiseQueue = void 0; class LimitPromiseQueue { constructor(max) { this.max = max, this._count = 0, this._pendingTaskQueue = []; } call(caller, ...arg) { return new Promise(((resolve, reject) => { const task = this._createTask(caller, arg, resolve, reject); this._count >= this.max ? this._pendingTaskQueue.push(task) : task(); })); } _createTask(caller, arg, resolve, reject) { return () => { this._count++, caller(...arg).then(resolve).catch(reject).finally((() => { if (this._count--, this._pendingTaskQueue.length) { this._pendingTaskQueue.shift()(); } })); }; } } exports.LimitPromiseQueue = LimitPromiseQueue; //# sourceMappingURL=LimitPromiseQueue.js.map