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

Method waitForConnected

cli/src/api/apiSession.ts:683–714  ·  view source on GitHub ↗
(timeoutMs: number)

Source from the content-addressed store, hash-verified

681 }
682
683 private async waitForConnected(timeoutMs: number): Promise<boolean> {
684 if (this.socket.connected) {
685 return true
686 }
687
688 this.socket.connect()
689
690 return await new Promise<boolean>((resolve) => {
691 let settled = false
692
693 const cleanup = () => {
694 this.socket.off('connect', onConnect)
695 clearTimeout(timeout)
696 }
697
698 const onConnect = () => {
699 if (settled) return
700 settled = true
701 cleanup()
702 resolve(true)
703 }
704
705 const timeout = setTimeout(() => {
706 if (settled) return
707 settled = true
708 cleanup()
709 resolve(false)
710 }, Math.max(0, timeoutMs))
711
712 this.socket.on('connect', onConnect)
713 })
714 }
715
716 private async drainLock(lock: AsyncLock, timeoutMs: number): Promise<boolean> {
717 if (timeoutMs <= 0) {

Callers 1

flushMethod · 0.95

Calls 3

cleanupFunction · 0.50
connectMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected