Files
flynn/src/daemon/lifecycle.ts
T
William Valentin 6090508bad style: auto-fix ESLint issues (curly braces and formatting)
- Add curly braces to all if/else/for/while statements
- Fix indentation and trailing spaces
- Auto-fixed 372 linting errors using eslint --fix
- Remaining issues are warnings only (non-null assertions, explicit any types)
2026-02-11 10:30:24 -08:00

35 lines
801 B
TypeScript

type ShutdownHandler = () => Promise<void>;
export class Lifecycle {
private shutdownHandlers: ShutdownHandler[] = [];
private shuttingDown = false;
private _isRunning = true;
get isRunning(): boolean {
return this._isRunning;
}
onShutdown(handler: ShutdownHandler): void {
this.shutdownHandlers.push(handler);
}
async shutdown(): Promise<void> {
if (this.shuttingDown) {return;}
this.shuttingDown = true;
this._isRunning = false;
console.log('Shutting down...');
// Execute handlers in reverse order (LIFO)
for (const handler of [...this.shutdownHandlers].reverse()) {
try {
await handler();
} catch (error) {
console.error('Shutdown handler error:', error);
}
}
console.log('Shutdown complete');
}
}