MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / pollUntil

Function pollUntil

apps/api/e2e/lib.ts:50–62  ·  view source on GitHub ↗
(
  fn: () => Promise<T>,
  { timeoutMs = 30_000, intervalMs = 750 } = {}
)

Source from the content-addressed store, hash-verified

48
49/** Poll `fn` until it returns a truthy value or the timeout elapses. */
50export async function pollUntil<T>(
51 fn: () => Promise<T>,
52 { timeoutMs = 30_000, intervalMs = 750 } = {}
53): Promise<T | null> {
54 const deadline = Date.now() + timeoutMs;
55 // biome-ignore lint/nursery/noConstantCondition: poll loop
56 while (true) {
57 const value = await fn();
58 if (value) return value;
59 if (Date.now() >= deadline) return null;
60 await sleep(intervalMs);
61 }
62}
63
64// ── Report framework ──────────────────────────────────────────────────────
65type Result = { scenario: string; name: string; ok: boolean; detail?: string };

Callers 6

settleFunction · 0.90
scenarioSingleSessionFunction · 0.90
scenarioBoundaryFunction · 0.90
scenarioReplayFunction · 0.90
scenarioIdentifyFunction · 0.90

Calls 2

fnFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected