histoire
Version:
A fast story book powered by Vite
12 lines (11 loc) • 448 B
JavaScript
/**
* Run async work over items with bounded parallelism, overlapping filesystem latency.
* Operations must handle their own failures; a rejection stops remaining items.
*/
export async function forEachVisualConcurrent(items, limit, operation) {
let next = 0;
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
while (next < items.length)
await operation(items[next++]);
}));
}