export async function startPolling < Result > ( fn , validate , interval , maxAttempts ) { let attempts = 0 ; const checkCondition = ( resolve , reject ) : void => { Promise . resolve ( fn ( ) ) . then ( ( result ) => { if ( validate ( result ) ) { resolve ( ) ; } else if ( attempts < maxAttempts ) { attempts += 1 ; setTimeout ( checkCondition , interval , resolve , reject ) ; } else { reject ( new Error ( "AsyncPoller: reached timeout" ) ) ; } } ) . catch ( ( err ) => { reject ( err ) ; } ) ; } ; return new Promise < void > ( checkCondition ) ; }