UNPKG

sf-decomposer

Version:

Split large Salesforce metadata files into version-control-friendly pieces and rebuild deployment-ready files.

33 lines 1.01 kB
'use strict'; /** * Creates a concurrency limiter that ensures at most `concurrency` async tasks * run simultaneously. Returns a scheduler function with the same call signature * as the p-limit package: `limit(fn, ...args)` enqueues the task and returns a * Promise that resolves/rejects with the task's result. */ export function pLimit(concurrency) { let active = 0; const queue = []; function next() { if (queue.length === 0 || active >= concurrency) return; active++; const run = queue.shift(); run(); } return function limit(fn) { return new Promise((resolve, reject) => { queue.push(() => { Promise.resolve() .then(() => fn()) .then(resolve, reject) .finally(() => { active--; next(); }); }); next(); }); }; } //# sourceMappingURL=pLimit.js.map