export class Concurrently { /**
     * Keep executing the async function in the background until the predicate
     * returns true.  This can be used for testing or where we expect a value
     * to be updated yet have no event notification of when it will actually
     * happen.
     */ public static waitForPredicate < T > ( callable , predicate , intervalMS = 250 ) { return new Promise < T > ( ( resolve , reject ) => { const executor = ( ) => { const doThen = ( val ) => { if ( predicate ( val ) ) { resolve ( val ) ; return ; } else { setTimeout ( executor , intervalMS ) ; } } ; const doCatch = ( err ) => { reject ( err ) ; } ; callable ( ) . then ( val => doThen ( val ) ) . catch ( err => doCatch ( err ) ) ; } ; setTimeout ( executor , 0 ) ; } ) ; } } export interface Callable < T > { ( ) : Promise < T > ; } export interface Predicate < T > { ( val ) : boolean ; }