fdcee08460
Extract 30+ single-responsibility modules from manager.ts (1556 LOC): - task lifecycle: task-starter, task-completer, task-canceller, task-resumer - task queries: task-queries, task-poller, task-queue-processor - notifications: notification-builder, notification-tracker, parent-session-notifier - session handling: session-validator, session-output-validator, session-todo-checker - spawner: spawner/ directory with focused spawn modules - utilities: duration-formatter, error-classifier, message-storage-locator - result handling: result-handler-context, background-task-completer - shutdown: background-manager-shutdown, process-signal
20 lines
581 B
TypeScript
20 lines
581 B
TypeScript
export type ProcessCleanupEvent = NodeJS.Signals | "beforeExit" | "exit"
|
|
|
|
export function registerProcessSignal(
|
|
signal: ProcessCleanupEvent,
|
|
handler: () => void,
|
|
exitAfter: boolean
|
|
): () => void {
|
|
const listener = () => {
|
|
handler()
|
|
if (exitAfter) {
|
|
// Set exitCode and schedule exit after delay to allow other handlers to complete async cleanup
|
|
// Use 6s delay to accommodate LSP cleanup (5s timeout + 1s SIGKILL wait)
|
|
process.exitCode = 0
|
|
setTimeout(() => process.exit(), 6000)
|
|
}
|
|
}
|
|
process.on(signal, listener)
|
|
return listener
|
|
}
|