(options?: { timeoutMs?: number })
| 740 | } |
| 741 | |
| 742 | async flush(options?: { timeoutMs?: number }): Promise<void> { |
| 743 | const deadlineMs = Date.now() + (options?.timeoutMs ?? 5_000) |
| 744 | |
| 745 | const remainingMs = () => Math.max(0, deadlineMs - Date.now()) |
| 746 | |
| 747 | await this.drainLock(this.metadataLock, remainingMs()) |
| 748 | await this.drainLock(this.agentStateLock, remainingMs()) |
| 749 | |
| 750 | if (remainingMs() === 0) { |
| 751 | return |
| 752 | } |
| 753 | |
| 754 | const connected = await this.waitForConnected(remainingMs()) |
| 755 | if (!connected) { |
| 756 | return |
| 757 | } |
| 758 | |
| 759 | const pingTimeoutMs = remainingMs() |
| 760 | if (pingTimeoutMs === 0) { |
| 761 | return |
| 762 | } |
| 763 | |
| 764 | try { |
| 765 | await this.socket.timeout(pingTimeoutMs).emitWithAck('ping') |
| 766 | } catch { |
| 767 | // best effort |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | close(): void { |
| 772 | this.rpcHandlerManager.onSocketDisconnect() |
no test coverage detected