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

Function waitFor

src/services/api/openAICompatWsV2Native.test.ts:414–434  ·  view source on GitHub ↗
(
  predicate: () => boolean,
  label: string,
  timeoutMs = 2000,
)

Source from the content-addressed store, hash-verified

412})
413
414function waitFor(
415 predicate: () => boolean,
416 label: string,
417 timeoutMs = 2000,
418): Promise<void> {
419 const deadline = Date.now() + timeoutMs
420 return new Promise((resolve, reject) => {
421 const tick = () => {
422 if (predicate()) {
423 resolve()
424 return
425 }
426 if (Date.now() >= deadline) {
427 reject(new Error(`timed out waiting for ${label}`))
428 return
429 }
430 setTimeout(tick, 10)
431 }
432 tick()
433 })
434}
435
436function createNativeWsV2LoopbackServer(options?: {
437 readonly keepRequestsOpen?: boolean

Callers 1

Calls 1

tickFunction · 0.70

Tested by

no test coverage detected