import { Tick } from "./tick" ; param condition param maxTime returns export async function waitUntil ( condition , maxTime ? ) { const start = Date . now ( ) ; if ( typeof condition !== "function" ) { return ! ! condition ; } if ( ! maxTime || typeof maxTime !== "number" ) { maxTime = Infinity ; } return new Promise < boolean > ( ( resolve ) => { const tick = new Tick ( ( ) => { const now = Date . now ( ) ; const result = condition ( ) ; if ( now - start >= maxTime ! ) { tick . destroy ( ) ; resolve ( false ) ; return ; } const handle = ( res ) => { if ( res ) { tick . destroy ( ) ; resolve ( true ) ; } } ; if ( result instanceof Promise ) { result . then ( handle ) ; return ; } handle ( result ) ; } ) ; tick . start ( ) ; } ) ; } param duration export async function waitFor ( duration ) { return new Promise < void > ( ( resolve ) => { window . setTimeout ( resolve , duration ) ; } ) ; }