fixed priority shutdown
This commit is contained in:
parent
6d5d746f68
commit
5929612e36
6 changed files with 113 additions and 46 deletions
|
|
@ -9,7 +9,7 @@ import type { ShutdownResult } from './types';
|
|||
|
||||
// Core shutdown classes and types
|
||||
export { Shutdown } from './shutdown';
|
||||
export type { ShutdownCallback, ShutdownOptions, ShutdownResult } from './types';
|
||||
export type { ShutdownCallback, ShutdownOptions, ShutdownResult, PrioritizedShutdownCallback } from './types';
|
||||
|
||||
// Global singleton instance
|
||||
let globalInstance: Shutdown | null = null;
|
||||
|
|
@ -31,8 +31,29 @@ function getGlobalInstance(): Shutdown {
|
|||
/**
|
||||
* Register a cleanup callback that will be executed during shutdown
|
||||
*/
|
||||
export function onShutdown(callback: () => Promise<void> | void): void {
|
||||
getGlobalInstance().onShutdown(callback);
|
||||
export function onShutdown(callback: () => Promise<void> | void, priority?: number, name?: string): void {
|
||||
getGlobalInstance().onShutdown(callback, priority, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a high priority shutdown callback (for queues, critical services)
|
||||
*/
|
||||
export function onShutdownHigh(callback: () => Promise<void> | void, name?: string): void {
|
||||
getGlobalInstance().onShutdownHigh(callback, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a medium priority shutdown callback (for databases, connections)
|
||||
*/
|
||||
export function onShutdownMedium(callback: () => Promise<void> | void, name?: string): void {
|
||||
getGlobalInstance().onShutdownMedium(callback, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a low priority shutdown callback (for loggers, cleanup)
|
||||
*/
|
||||
export function onShutdownLow(callback: () => Promise<void> | void, name?: string): void {
|
||||
getGlobalInstance().onShutdownLow(callback, name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue