fix: address v2 stack review findings

This commit is contained in:
ajnart committed 2026-08-20 13:08:54 +02:00
1 parent 53b518960c
commit 263702210a
48 files changed
+1235 -530

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
export async function mapWithConcurrency<T, U>(
values: readonly T[],
concurrency: number,
mapper: (value: T, index: number) => Promise<U>,
): Promise<U[]> {
if (!Number.isSafeInteger(concurrency) || concurrency < 1) {
throw new Error("Concurrency must be a positive integer");
}
const results: U[] = [];
let nextIndex = 0;
const workerCount = Math.min(concurrency, values.length);
const workers = Array.from({ length: workerCount }, async () => {
while (nextIndex < values.length) {
const index = nextIndex;
nextIndex += 1;
results[index] = await mapper(values[index] as T, index);
}
});
await Promise.all(workers);
return results;
}
+1
View File
@@ -13,3 +13,4 @@ export * from "./theme";
export * from "./function";
export * from "./grid-algorithm";
export * from "./id";
export * from "./async";