Files
romm/frontend/src/v2/utils/settleWithLimit.ts
Georges-Antoine Assi e4cf33a344 Size gallery bulk actions for whole-result selections
Bulk status bounds its per-ROM fan-out to four requests in flight. Bulk
download posts the ID list to a new POST /roms/download/selection, which
stores it in Redis and returns a token that GET /roms/download reads, so
the list no longer rides in the URL and cannot overflow it. The download
now reports a failure instead of always showing the optimistic snackbar.
The delete dialog renders its rows 50 at a time behind a "Show more"
button, reads fs membership from a Set, and writes scan exclusions one at
a time since each call rewrites the config file.

Fixes #4460

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 14:46:30 -04:00

25 lines
737 B
TypeScript

/** `Promise.allSettled` over `items`, with at most `limit` tasks in flight. */
export async function settleWithLimit<T, R>(
items: readonly T[],
limit: number,
task: (item: T) => Promise<R>,
): Promise<PromiseSettledResult<R>[]> {
const results = new Array<PromiseSettledResult<R>>(items.length);
let next = 0;
async function worker() {
while (next < items.length) {
const i = next++;
try {
results[i] = { status: "fulfilled", value: await task(items[i]) };
} catch (reason) {
results[i] = { status: "rejected", reason };
}
}
}
const workers = Math.max(1, Math.min(limit, items.length));
await Promise.all(Array.from({ length: workers }, worker));
return results;
}