website
git clone https://git.pyrossh.dev/website
木 Personal website of pyrossh. Built with astrojs, shiki, vite.
src/_helpers/pool.js
/**
* Run `mapper` over `items` with at most `limit` concurrent in-flight
* calls, preserving input order in the result. The git subprocess calls
* this feeds are I/O-bound (fork+exec, not CPU), so running them
* concurrently instead of one-at-a-time cuts wall-clock time roughly
* proportional to `limit` on a multi-core machine.
*/
export const mapPool = async (items, limit, mapper) => {
const results = new Array(items.length);
let next = 0;
const workers = Array.from({ length: Math.min(limit, items.length) }, async () => {
while (next < items.length) {
const i = next++;
results[i] = await mapper(items[i], i);
}
});
await Promise.all(workers);
return results;
};