()
| 354 | // Resolves the engine a call was started on, so a call in flight while the |
| 355 | // engine is being retired still finishes on it. |
| 356 | const ensureEngine = async (): Promise<MCPEngine> => { |
| 357 | // shutdown() stops only the engines it can see; never start one after it. |
| 358 | if (!engine && shuttingDown) throw new Error('codegraph is shutting down'); |
| 359 | if (!engine) { |
| 360 | engine = deps.makeEngine(); |
| 361 | engineReady = engine.ensureInitialized(deps.root).catch(() => { /* degraded */ }); |
| 362 | } |
| 363 | const current = engine; |
| 364 | await engineReady; |
| 365 | return current; |
| 366 | }; |
| 367 | // Stop the in-process engine once the calls it is serving have answered. |
| 368 | // Stopping it releases the writer lock if it held one. |
| 369 | const retireEngine = async (): Promise<void> => { |
no test coverage detected