chore: initialize recovered claude workspace
This commit is contained in:
25
src/utils/cleanupRegistry.ts
Normal file
25
src/utils/cleanupRegistry.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Global registry for cleanup functions that should run during graceful shutdown.
|
||||
* This module is separate from gracefulShutdown.ts to avoid circular dependencies.
|
||||
*/
|
||||
|
||||
// Global registry for cleanup functions
|
||||
const cleanupFunctions = new Set<() => Promise<void>>()
|
||||
|
||||
/**
|
||||
* Register a cleanup function to run during graceful shutdown.
|
||||
* @param cleanupFn - Function to run during cleanup (can be sync or async)
|
||||
* @returns Unregister function that removes the cleanup handler
|
||||
*/
|
||||
export function registerCleanup(cleanupFn: () => Promise<void>): () => void {
|
||||
cleanupFunctions.add(cleanupFn)
|
||||
return () => cleanupFunctions.delete(cleanupFn) // Return unregister function
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all registered cleanup functions.
|
||||
* Used internally by gracefulShutdown.
|
||||
*/
|
||||
export async function runCleanupFunctions(): Promise<void> {
|
||||
await Promise.all(Array.from(cleanupFunctions).map(fn => fn()))
|
||||
}
|
||||
Reference in New Issue
Block a user