/**
 * A wrapper-promise which rejects when discarded
 */ export class DiscardablePromise < T > implements PromiseLike < T > { constructor ( private promise ) { } static discarded = Symbol ( 'discarded' ) ; isDiscarded : boolean ; then < TResult1 = T , TResult2 = never > ( onfulfilled ? , onrejected ? ) { return this . promise . then ( async ( x ) => { if ( this . isDiscarded ) { return Promise . reject ( DiscardablePromise . discarded ) ; } else { return Promise . resolve ( x ) ; } } ) . then ( onfulfilled , onrejected ) ; } discard ( ) { this . isDiscarded = true ; } }