fix: improve shutdown and project continuity

This commit is contained in:
lofyer
2026-08-07 18:46:26 +08:00
parent 53d18e2b06
commit 954b42ef55
10 changed files with 245 additions and 34 deletions
+18
View File
@@ -0,0 +1,18 @@
export async function waitForCleanup(
cleanup: Promise<unknown>,
timeoutMs: number
): Promise<boolean> {
let timeout: NodeJS.Timeout | undefined
const timedOut = new Promise<false>((resolve) => {
timeout = setTimeout(() => resolve(false), timeoutMs)
})
const settled = Promise.resolve(cleanup).then(
() => true as const,
() => true as const
)
const completed = await Promise.race([settled, timedOut])
if (timeout) {
clearTimeout(timeout)
}
return completed
}