UNPKG

wrap-git

Version:

Wraps GitHub profile and provides summarized details about repos, commits and language coverages for a given profile.

27 lines (26 loc) 816 B
export async function throttleAll(items, limit, asyncFn) { const results = []; let activeCount = 0; let currentIndex = 0; return new Promise((resolve, reject) => { const next = () => { if (currentIndex >= items.length && activeCount === 0) { return resolve(results); } while (activeCount < limit && currentIndex < items.length) { const i = currentIndex++; activeCount++; asyncFn(items[i], i) .then((res) => { results[i] = res; }) .catch(reject) .finally(() => { activeCount--; next(); }); } }; next(); }); }