Provides a centralized registry for registering and executing cleanup functions during application termination.
// Source: https://github.com/chauncygu/collection-claude-code-source-code | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/**
* 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 {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key