MCPcopy Create free account
hub / github.com/Noumena-Network/code / withTimeout

Function withTimeout

src/remote/appServer/client.test.ts:24–36  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  label: string,
  timeoutMs = 3000,
)

Source from the content-addressed store, hash-verified

22})
23
24function withTimeout<T>(
25 promise: Promise<T>,
26 label: string,
27 timeoutMs = 3000,
28): Promise<T> {
29 let timer: NodeJS.Timeout | undefined
30 const timeout = new Promise<never>((_, reject) => {
31 timer = setTimeout(() => reject(new Error(`timed out: ${label}`)), timeoutMs)
32 })
33 return Promise.race([promise, timeout]).finally(() => {
34 if (timer) clearTimeout(timer)
35 })
36}
37
38class FakePeer {
39 private readonly queued: unknown[] = []

Callers 1

nextMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected