MCPcopy Create free account
hub / github.com/tiann/hapi / flush

Method flush

cli/src/api/apiSession.ts:742–769  ·  view source on GitHub ↗
(options?: { timeoutMs?: number })

Source from the content-addressed store, hash-verified

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()

Callers 2

archiveAndCloseFunction · 0.45
runAgentSessionFunction · 0.45

Calls 2

drainLockMethod · 0.95
waitForConnectedMethod · 0.95

Tested by

no test coverage detected