MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / withTimeout

Function withTimeout

src/mcp/client.ts:144–153  ·  view source on GitHub ↗
(promise: Promise<T>, ms: number, message: string)

Source from the content-addressed store, hash-verified

142}
143
144function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
145 let timer: ReturnType<typeof setTimeout> | undefined
146 const cap = new Promise<never>((_, reject) => {
147 timer = setTimeout(() => reject(new Error(message)), ms)
148 timer.unref?.()
149 })
150 return Promise.race([promise, cap]).finally(() => {
151 if (timer) clearTimeout(timer)
152 }) as Promise<T>
153}

Callers 1

connectMcpServerFunction · 0.85

Calls 1

unrefMethod · 0.80

Tested by

no test coverage detected