UNPKG

p-all-limit

Version:

```ts import { promiseAllLimit } from 'p-all-limit'

31 lines 814 B
// p-all-limit.ts var promiseAllLimit = (array, iterator, limit) => { let inFlight = 0; return new Promise((resolve, reject) => { let results = []; let itemIndex = -1; const next = () => { if (array.length === 0 && inFlight === 0) { return resolve(results); } while (inFlight < limit && array.length > 0) { inFlight++; const nextItem = array.shift(); itemIndex += 1; const currentIndexForThisClosure = itemIndex; iterator(nextItem).then((singleResult) => { results[currentIndexForThisClosure] = singleResult; inFlight--; next(); }).catch((error) => { reject(error); }); } }; next(); }); }; export { promiseAllLimit }; //# sourceMappingURL=p-all-limit.mjs.map