type K = ( ) => void ; type KK = ( f : K ) => void ; const kk = ( f ) => { } ; hidden export class CancellationToken { static neverCancelToken ( ) { return new CancellationToken ( ) ; } isCancellationRequested = false ; onCancelled : K [ ] = [ ] ; promise : Promise < void > ; constructor ( defineUserCancels = kk ) { this . onCancelled . push ( ( ) => ( this . isCancellationRequested = true ) ) ; this . promise = new Promise ( ( resolve ) => this . onCancelled . push ( resolve ) ) ; defineUserCancels ( ( f ) => { this . onCancelled . push ( f ) ; return ; } ) ; } cancel ( ) { this . onCancelled . forEach ( ( x ) => x ( ) ) ; } }