/** * Cleanup Registry Module * * Provides a centralized cleanup handler registry for graceful shutdown. * Resources (FileWatcher, LanceDB, IntegrityEngine, etc.) register their * cleanup handlers here, and they are called in LIFO order during shutdown. * * Features: * - Register/unregister cleanup handlers * - Run all handlers in reverse order (LIFO) for proper dependency handling * - Prevent duplicate cleanup runs * - Configurable timeout for cleanup operations * - Error isolation (one handler failure doesn't stop others) */ /** * Cleanup handler function type * Should clean up resources and return a promise */ export type CleanupHandler = () => Promise; /** * Default timeout for cleanup operations in milliseconds (30 seconds) */ export declare const DEFAULT_CLEANUP_TIMEOUT = 30000; /** * Register a cleanup handler to be called on shutdown. * Handlers are called in reverse order (LIFO) to properly handle dependencies. * * @param handler - The cleanup handler function * @param name - Optional name for logging (defaults to 'anonymous') * * @example * ```typescript * // In FileWatcher.start() * registerCleanup(async () => { * await this.stop(); * }, 'FileWatcher'); * ``` */ export declare function registerCleanup(handler: CleanupHandler, name?: string): void; /** * Unregister a cleanup handler. * Used when a resource is explicitly closed before shutdown. * * @param handler - The cleanup handler function to remove * * @example * ```typescript * // In FileWatcher.stop() * unregisterCleanup(this.cleanupHandler); * ``` */ export declare function unregisterCleanup(handler: CleanupHandler): void; /** * Run all cleanup handlers in reverse order (LIFO). * This ensures that resources registered later (which may depend on earlier ones) * are cleaned up first. * * @param timeoutMs - Optional timeout in milliseconds (default: 30 seconds) * @returns Promise that resolves when all handlers have been called * * @example * ```typescript * // In shutdown handler * await runCleanup(); * ``` */ export declare function runCleanup(timeoutMs?: number): Promise; /** * Check if shutdown is in progress. * Useful for resources to skip operations during shutdown. * * @returns true if runCleanup() has been called but not completed */ export declare function isShutdownInProgress(): boolean; /** * Check if cleanup has completed. * * @returns true if runCleanup() has completed */ export declare function isCleanupCompleted(): boolean; /** * Get the number of registered cleanup handlers. * Useful for testing and debugging. * * @returns Number of registered handlers */ export declare function getCleanupHandlerCount(): number; /** * Reset the cleanup registry state. * **ONLY FOR TESTING** - do not use in production code. */ export declare function resetCleanupRegistry(): void; //# sourceMappingURL=cleanup.d.ts.map