UNPKG

supamend

Version:

Pluggable DevSecOps Security Scanner with 10+ scanners and multiple reporting channels

40 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParallelExecutor = void 0; class ParallelExecutor { static async executeWithLimit(items, executor, concurrencyLimit = 3) { const results = []; const executing = []; for (const item of items) { const promise = executor(item) .then(result => { results.push({ item, result }); }) .catch(error => { results.push({ item, error }); }); executing.push(promise); if (executing.length >= concurrencyLimit) { await Promise.race(executing); // Remove completed promises const stillPending = []; for (const p of executing) { try { await Promise.race([p, Promise.resolve()]); // If we get here, the promise is resolved } catch { // Promise is still pending or rejected, keep it stillPending.push(p); } } executing.length = 0; executing.push(...stillPending); } } await Promise.all(executing); return results; } } exports.ParallelExecutor = ParallelExecutor; //# sourceMappingURL=parallel-executor.js.map