function delayCheck < T > ( timeout , delay , checkFn , runFn ? , runFirst = true ) { if ( runFirst && runFn ) { runFn ( ) ; } while ( timeout > 0 ) { timeout -= delay ; const result = checkFn ( ) ; if ( result ) { return result ; } if ( runFn ) { runFn ( ) ; } sleep ( delay ) ; } return false ; } function delayRun ( delay , runFn , checkFn , retries = 3 ) { let left = retries ; while ( left > 0 ) { if ( ! checkFn ( ) ) { left -= 1 ; sleep ( delay ) ; } else { left = retries ; runFn ( ) ; } } } export { delayCheck , delayRun } ;