export async function delayWhileSync ( pollMs , predicate , timeout = 0 , timeoutErrorMessage = "Timed out" ) { return new Promise ( ( resolve , reject ) : void => { const start = Date . now ( ) ; const handler = setInterval ( ( ) => { try { if ( ! predicate ( ) ) { clearInterval ( handler ) ; resolve ( ) ; } else if ( timeout > 0 && Date . now ( ) - start > timeout ) { reject ( new Error ( timeoutErrorMessage ) ) ; } } catch ( err ) { reject ( err ) ; } } , pollMs ) ; } ) ; }