(
fn: () => Promise<T>,
{ timeoutMs = 30_000, intervalMs = 750 } = {}
)
| 48 | |
| 49 | /** Poll `fn` until it returns a truthy value or the timeout elapses. */ |
| 50 | export 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 ────────────────────────────────────────────────────── |
| 65 | type Result = { scenario: string; name: string; ok: boolean; detail?: string }; |
no test coverage detected