(options: ParentMonitorOptions)
| 112 | } |
| 113 | |
| 114 | export function startParentMonitor(options: ParentMonitorOptions): () => void { |
| 115 | if (!Number.isFinite(options.parentPid) || options.parentPid <= 1 || options.parentPid === process.pid) { |
| 116 | return () => { }; |
| 117 | } |
| 118 | |
| 119 | const pollIntervalMs = Math.max(MIN_PARENT_POLL_MS, Math.floor(options.pollIntervalMs ?? DEFAULT_PARENT_POLL_MS)); |
| 120 | const isAlive = options.isProcessAlive ?? isProcessAlive; |
| 121 | let stopped = false; |
| 122 | |
| 123 | const stop = (): void => { |
| 124 | if (stopped) return; |
| 125 | stopped = true; |
| 126 | clearInterval(interval); |
| 127 | }; |
| 128 | |
| 129 | const interval = setInterval(() => { |
| 130 | if (stopped) return; |
| 131 | if (process.ppid !== options.parentPid || !isAlive(options.parentPid)) { |
| 132 | stop(); |
| 133 | options.onParentExit(); |
| 134 | } |
| 135 | }, pollIntervalMs); |
| 136 | |
| 137 | unrefHandle(interval); |
| 138 | return stop; |
| 139 | } |
| 140 | |
| 141 | export async function runCleanup(options: CleanupOptions): Promise<void> { |
| 142 | options.cancelEmbeddings?.(); |
no test coverage detected