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