import { Shutdown } from './shutdown'; import type { ShutdownResult } from './types'; /** * @stock-bot/shutdown - Shutdown management library * * Main exports for the shutdown library */ // Core shutdown classes and types export { Shutdown } from './shutdown'; export type { ShutdownCallback, ShutdownOptions, ShutdownResult } from './types'; // Global singleton instance let globalInstance: Shutdown | null = null; /** * Get the global shutdown instance (creates one if it doesn't exist) */ function getGlobalInstance(): Shutdown { if (!globalInstance) { globalInstance = Shutdown.getInstance(); } return globalInstance; } /** * Convenience functions for global shutdown management */ /** * Register a cleanup callback that will be executed during shutdown */ export function onShutdown(callback: () => Promise | void): void { getGlobalInstance().onShutdown(callback); } /** * Set the shutdown timeout in milliseconds */ export function setShutdownTimeout(timeout: number): void { getGlobalInstance().setTimeout(timeout); } /** * Check if shutdown is currently in progress */ export function isShuttingDown(): boolean { return globalInstance?.isShutdownInProgress() || false; } /** * Get the number of registered shutdown callbacks */ export function getShutdownCallbackCount(): number { return globalInstance?.getCallbackCount() || 0; } /** * Manually initiate graceful shutdown */ export function initiateShutdown(signal?: string): Promise { return getGlobalInstance().shutdown(signal); } /** * Manually initiate graceful shutdown and exit the process */ export function shutdownAndExit(signal?: string, exitCode = 0): Promise { return getGlobalInstance().shutdownAndExit(signal, exitCode); } /** * Reset the global instance (mainly for testing) */ export function resetShutdown(): void { globalInstance = null; Shutdown.reset(); }