fix: harden scoped tools and settings persistence

This commit is contained in:
lofyer
2026-08-13 14:56:53 +08:00
parent bf1ec5d2f1
commit aab961226f
62 changed files with 4343 additions and 1314 deletions
+24
View File
@@ -16,3 +16,27 @@ export async function waitForCleanup(
}
return completed
}
export type CleanupOperation = () => unknown | Promise<unknown>
export async function settleCleanupPhases(
phases: readonly (readonly CleanupOperation[])[]
): Promise<void> {
for (const phase of phases) {
await Promise.allSettled(
phase.map((operation) => Promise.resolve().then(operation))
)
}
}
export async function runCleanupBeforeDeadline(
cleanup: Promise<unknown>,
timeoutMs: number,
finalize: () => unknown | Promise<unknown>
): Promise<boolean> {
const completed = await waitForCleanup(cleanup, timeoutMs)
if (completed) {
await finalize()
}
return completed
}