waitFor
export const waitFor = async (cond: () => boolean | Promise<boolean>, ms = 20000) => { for (const end = Date.now() + ms; Date.now() < end; await new Promise((r) => setTimeout(r, 150))) if (await cond()) return; throw new Error("timed out waiting"); }