import { BehaviorSubject , Subscription } from 'rxjs' ; export default class AsyncStatus { protected ready : boolean = false ; protected subject$ : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ; isReady ( ) { return this . ready ; } done ( ) { if ( this . ready ) { } this . ready = true ; this . emit ( ) ; return this ; } emit ( ) { this . subject$ . next ( this . ready ) ; return this ; } untilReady ( ) { if ( this . isReady ( ) ) { return Promise . resolve ( null ) ; } return new Promise ( resolve => { let subscription ; subscription = this . subject$ . subscribe ( ( ) => { if ( this . isReady ( ) ) { subscription . unsubscribe ( ) ; resolve ( null ) ; } } ) ; } ) ; } static _ ( ) { return new AsyncStatus ( ) ; } }