()
| 499 | |
| 500 | // ---- daemon connection (background) ---- |
| 501 | const connectDaemon = async (): Promise<net.Socket | null> => { |
| 502 | let socket: net.Socket | null = null; |
| 503 | try { socket = await deps.getDaemonSocket(); } catch { socket = null; } |
| 504 | // `socket.destroyed`: the connect-window error guard above can absorb an |
| 505 | // 'error' that already destroyed the socket before we got here (#974) — treat |
| 506 | // a dead socket as "no daemon" so we cleanly fall back to the in-process engine. |
| 507 | if (socket && (socket.destroyed || shuttingDown)) { |
| 508 | try { socket.destroy(); } catch { /* ignore */ } |
| 509 | socket = null; |
| 510 | } |
| 511 | return socket; |
| 512 | }; |
| 513 | // Every buffered call binds to the engine now, so a later retirement waits for all of them. |
| 514 | const serveBufferedLocally = (): void => { |
| 515 | for (const line of pending.splice(0)) void handleLocally(line); |
no test coverage detected