( timeoutMs: number, settings: DaemonClientSettings, launch: DaemonStartupLaunch, )
| 357 | } |
| 358 | |
| 359 | async function waitForDaemonStartup( |
| 360 | timeoutMs: number, |
| 361 | settings: DaemonClientSettings, |
| 362 | launch: DaemonStartupLaunch, |
| 363 | ): Promise<DaemonStartupWaitResult> { |
| 364 | const start = Date.now(); |
| 365 | let earlyExit: ExecDetachedExit | undefined; |
| 366 | void launch.exited.then((exit) => { |
| 367 | earlyExit = exit; |
| 368 | }); |
| 369 | |
| 370 | while (Date.now() - start < timeoutMs) { |
| 371 | if (earlyExit) return { kind: 'early_exit', exit: earlyExit }; |
| 372 | const info = readDaemonInfo(settings.paths.infoPath); |
| 373 | if (info && (await canConnect(info, settings.transportPreference))) { |
| 374 | return { kind: 'ready', info }; |
| 375 | } |
| 376 | if (earlyExit) return { kind: 'early_exit', exit: earlyExit }; |
| 377 | await sleep(100); |
| 378 | } |
| 379 | return { kind: 'timeout' }; |
| 380 | } |
| 381 | |
| 382 | function startDaemon(settings: DaemonClientSettings): DaemonStartupLaunch { |
| 383 | const launchSpec = resolveDaemonLaunchSpec(); |
no test coverage detected