fixed format issues

This commit is contained in:
Boki 2025-06-26 16:12:27 -04:00
parent a700818a06
commit 08f713d98b
55 changed files with 5680 additions and 5533 deletions

View file

@ -33,8 +33,14 @@ export class Shutdown {
/**
* Register a cleanup callback
*/
onShutdown(callback: ShutdownCallback, priority: number = SHUTDOWN_DEFAULTS.MEDIUM_PRIORITY, name?: string): void {
if (this.isShuttingDown) { return };
onShutdown(
callback: ShutdownCallback,
priority: number = SHUTDOWN_DEFAULTS.MEDIUM_PRIORITY,
name?: string
): void {
if (this.isShuttingDown) {
return;
}
this.callbacks.push({ callback, priority, name });
}
@ -42,14 +48,16 @@ export class Shutdown {
* Initiate graceful shutdown
*/
async shutdown(): Promise<void> {
if (this.isShuttingDown) { return };
if (this.isShuttingDown) {
return;
}
this.isShuttingDown = true;
const timeout = new Promise<never>((_, reject) =>
const timeout = new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error('Shutdown timeout')), this.shutdownTimeout)
);
try {
await Promise.race([this.executeCallbacks(), timeout]);
} catch (error) {
@ -60,7 +68,7 @@ export class Shutdown {
private async executeCallbacks(): Promise<void> {
const sorted = [...this.callbacks].sort((a, b) => a.priority - b.priority);
for (const { callback, name } of sorted) {
try {
await callback();
@ -71,10 +79,12 @@ export class Shutdown {
}
private setupSignalHandlers(): void {
if (this.signalHandlersRegistered) { return };
if (this.signalHandlersRegistered) {
return;
}
const signals: NodeJS.Signals[] = ['SIGTERM', 'SIGINT'];
signals.forEach(signal => {
process.once(signal, async () => {
if (!this.isShuttingDown) {
@ -87,7 +97,7 @@ export class Shutdown {
}
});
});
this.signalHandlersRegistered = true;
}
}
}