Files
reverse-engineering-anything/src/application/settleConcurrent.ts
T
morluto cb33fa8376 perf(doctor): slim cold CLI/MCP doctor module graphs and run probes concurrently
Record default catalog counts and digests in recordedCatalogDigests.js, reuse
the SHA-256-verified mcp-catalog.json in default rea mcp doctor runs, move
Windows existing-project Ghidra admission constants to GhidraAdmission, defer
BinaryTargetResolver and Kuna installation probes until needed, and join
independent Doctor host/provider/identity probes via settleConcurrent.

Statically loaded JS drops 7.03 MB -> 2.07 MB (-70.6%) for rea doctor/setup
(command_ms 440ms -> 207ms, -53.0%) and 5.71 MB -> 0.85 MB (-85.1%) for
rea mcp doctor.
2026-11-17 19:58:40 +08:00

30 lines
1.1 KiB
TypeScript

import { AnalysisError } from "../domain/analysisErrorBase.js";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
/**
* Join independent read-only inspections before surfacing any failure so peers
* finish handing retained resources to the owning scope first. Prefer physical
* failures and incomplete-cleanup attributions over plain cancellation.
*/
export const settleConcurrent = async <T extends readonly unknown[]>(tasks: {
[K in keyof T]: Promise<T[K]>;
}): Promise<T> => {
const settled = await Promise.allSettled(tasks);
const rejected = settled.flatMap((outcome) =>
outcome.status === "rejected" ? [outcome.reason] : [],
);
if (rejected.length > 0) {
const physical = rejected.find(
(cause) => !(cause instanceof AnalysisCancelledError),
);
if (physical !== undefined) throw physical;
const withCleanup = rejected.find(
(cause) => cause instanceof AnalysisError && cause.cleanupIncomplete,
);
throw withCleanup ?? rejected[0];
}
return settled.map((outcome) =>
outcome.status === "fulfilled" ? outcome.value : undefined,
) as unknown as T;
};