* Check if daemon is running by attempting to connect.
()
| 320 | * Check if daemon is running by attempting to connect. |
| 321 | */ |
| 322 | async isRunning(): Promise<boolean> { |
| 323 | return new Promise<boolean>((resolve) => { |
| 324 | const socket = net.createConnection(this.socketPath); |
| 325 | let settled = false; |
| 326 | |
| 327 | const finish = (value: boolean): void => { |
| 328 | if (settled) return; |
| 329 | settled = true; |
| 330 | try { |
| 331 | socket.destroy(); |
| 332 | } catch { |
| 333 | // ignore |
| 334 | } |
| 335 | resolve(value); |
| 336 | }; |
| 337 | |
| 338 | const timeoutId = setTimeout(() => { |
| 339 | finish(false); |
| 340 | }, this.timeout); |
| 341 | |
| 342 | socket.on('connect', () => { |
| 343 | clearTimeout(timeoutId); |
| 344 | finish(true); |
| 345 | }); |
| 346 | |
| 347 | socket.on('error', () => { |
| 348 | clearTimeout(timeoutId); |
| 349 | finish(false); |
| 350 | }); |
| 351 | }); |
| 352 | } |
| 353 | } |
no test coverage detected