import { sleep } from "./sleep" ; export async function waitFor ( iterations , pollSec , timeoutMsg , action ) { for ( let i = 0 ; i < iterations ; i ++ ) { if ( await action ( ) ) return ; await sleep ( pollSec * 1000 ) ; } throw new Error ( timeoutMsg ) ; } export async function waitForNoThrow ( iterations , pollSec , action ) { let lastError ; for ( let i = 0 ; i < iterations ; i ++ ) { try { await action ( ) ; return ; } catch ( e ) { lastError = e ; } await sleep ( pollSec * 1000 ) ; } throw lastError ; }