import { sleep } from "../../src/utils.js"; export type PollOptions = { timeoutMs?: number; intervalMs?: number; }; export async function pollUntil( fn: () => Promise, opts: PollOptions = {}, ): Promise { const timeoutMs = opts.timeoutMs ?? 2000; const intervalMs = opts.intervalMs ?? 25; const start = Date.now(); while (Date.now() - start < timeoutMs) { const value = await fn(); if (value !== null && value !== undefined) { return value; } await sleep(intervalMs); } return undefined; }