export default class Deferred < T > implements Promise < T > { protected subscribed = false ; private promise : Promise < T > ; private _resolve ! : ( result : T ) => void ; private _reject ! : ( reason : any ) => void ; [ Symbol . toStringTag ] = "Deferred" ; constructor ( ) { this . promise = new Promise ( ( resolve , reject ) => { this . _resolve = resolve ; this . _reject = reject ; } ) ; } protected resolve ( result ) { this . _resolve ( result ) ; } protected reject ( reason ) { this . _reject ( reason ) ; } then < TResult1 = T , TResult2 = never > ( onfulfilled ? , onrejected ? ) { this . subscribed = true ; return this . promise . then ( onfulfilled , onrejected ) ; } catch < TResult = never > ( onrejected ? ) { this . subscribed = true ; return this . promise . catch ( onrejected ) ; } finally ( onfinally ? ) { this . subscribed = true ; return this . promise . finally ( onfinally ) ; } }