Files
Chris Tate c08ab955ae Enforce linting and consistent source formatting
- Enforce oxlint and oxfmt for owned JavaScript and TypeScript with independent CI checks.
- Preserve compiler import boundaries and protected fixtures while cleaning up lint findings.
- Standardize source formatting and validate import, fixture, and embedded-source protections.
2026-10-05 17:51:24 -05:00

24 lines
875 B
JavaScript

/** Bounded build work that preserves manifest order and drains in-flight
* compilers before propagating a failure to the staging-directory cleanup. */
export async function parallelMap(items, width, task) {
if (!Number.isInteger(width) || width < 1) throw new Error("invalid build concurrency");
const results = new Array(items.length);
let next = 0;
let failed = false;
const workers = Array.from({ length: Math.min(width, items.length) }, async () => {
while (!failed && next < items.length) {
const index = next++;
try {
results[index] = await task(items[index]);
} catch (error) {
failed = true;
throw error;
}
}
});
const settled = await Promise.allSettled(workers);
const failure = settled.find((result) => result.status === "rejected");
if (failure) throw failure.reason;
return results;
}