finished shutdown lib

This commit is contained in:
Bojan Kucera 2025-06-07 10:40:08 -04:00
parent 97dcd30223
commit 13c2f10db9
4 changed files with 213 additions and 28 deletions

View file

@ -1,25 +1,25 @@
/**
* @stock-bot/shutdown - Graceful shutdown management library
* @stock-bot/shutdown - Shutdown management library
*
* Main exports for the shutdown library
*/
// Core shutdown classes and types
export { GracefulShutdown } from './graceful-shutdown.js';
export { Shutdown } from './shutdown.js';
export type { ShutdownCallback, ShutdownOptions, ShutdownResult } from './types.js';
import { GracefulShutdown } from './graceful-shutdown.js';
import { Shutdown } from './shutdown.js';
import type { ShutdownResult } from './types.js';
// Global singleton instance
let globalInstance: GracefulShutdown | null = null;
let globalInstance: Shutdown | null = null;
/**
* Get the global shutdown instance (creates one if it doesn't exist)
*/
function getGlobalInstance(): GracefulShutdown {
function getGlobalInstance(): Shutdown {
if (!globalInstance) {
globalInstance = GracefulShutdown.getInstance();
globalInstance = Shutdown.getInstance();
}
return globalInstance;
}
@ -42,13 +42,6 @@ export function setShutdownTimeout(timeout: number): void {
getGlobalInstance().setTimeout(timeout);
}
/**
* Enable or disable debug logging
*/
export function setShutdownDebug(enabled: boolean): void {
getGlobalInstance().setDebug(enabled);
}
/**
* Check if shutdown is currently in progress
*/
@ -82,5 +75,5 @@ export function shutdownAndExit(signal?: string, exitCode = 0): Promise<never> {
*/
export function resetShutdown(): void {
globalInstance = null;
GracefulShutdown.reset();
Shutdown.reset();
}