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

Method drainLock

cli/src/api/apiSession.ts:716–740  ·  view source on GitHub ↗
(lock: AsyncLock, timeoutMs: number)

Source from the content-addressed store, hash-verified

714 }
715
716 private async drainLock(lock: AsyncLock, timeoutMs: number): Promise<boolean> {
717 if (timeoutMs <= 0) {
718 return false
719 }
720
721 return await new Promise<boolean>((resolve) => {
722 let settled = false
723 let timeout: ReturnType<typeof setTimeout> | null = null
724
725 const finish = (value: boolean) => {
726 if (settled) return
727 settled = true
728 if (timeout) {
729 clearTimeout(timeout)
730 }
731 resolve(value)
732 }
733
734 timeout = setTimeout(() => finish(false), timeoutMs)
735
736 lock.inLock(async () => { })
737 .then(() => finish(true))
738 .catch(() => finish(false))
739 })
740 }
741
742 async flush(options?: { timeoutMs?: number }): Promise<void> {
743 const deadlineMs = Date.now() + (options?.timeoutMs ?? 5_000)

Callers 1

flushMethod · 0.95

Calls 1

inLockMethod · 0.80

Tested by

no test coverage detected