import { delayAsync } from '../../utils/delayAsync' ; export class TimeoutError extends Error { } export async function waitForActionAsync < T > ( { action , interval = 100 , maxWaitTime = 20000 , } ) { let complete ; const start = Date . now ( ) ; do { complete = await action ( ) ; await delayAsync ( interval ) ; if ( Date . now ( ) - start > maxWaitTime ) { break ; } } while ( ! complete ) ; return complete ; }