@@ -18,10 +18,6 @@ export interface Task<T> {
1818 ( ) : T ;
1919}
2020
21- // export interface IDisposable {
22- // dispose(): void;
23- // }
24-
2521export class Delayer < T > {
2622
2723 private timeout : any ;
@@ -30,29 +26,27 @@ export class Delayer<T> {
3026
3127 private doResolve : ( ( value ?: any | Promise < any > ) => void ) | null ;
3228
33- private doReject : ( err : any ) => void ;
34-
3529 private task : Task < T | Promise < T > > | null ;
3630
3731 constructor ( public defaultDelay : number ) {
3832 this . timeout = null ;
3933 this . completionPromise = null ;
4034 this . doResolve = null ;
41- this . doReject ;
4235 this . task = null ;
4336 }
4437
4538 trigger ( task : Task < T | Promise < T > > , delay : number = this . defaultDelay ) : Promise < T > {
4639 this . task = task ;
4740 this . cancelTimeout ( ) ;
4841
42+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
4943 if ( ! this . completionPromise ) {
5044 this . completionPromise = new Promise ( ( c , e ) => {
5145 this . doResolve = c ;
52- this . doReject = e ;
5346 } ) . then ( ( ) => {
5447 this . completionPromise = null ;
5548 this . doResolve = null ;
49+ // eslint-disable-next-line no-shadow
5650 const { task} = this ;
5751 this . task = null ;
5852
@@ -68,27 +62,10 @@ export class Delayer<T> {
6862 return this . completionPromise ;
6963 }
7064
71- // isTriggered(): boolean {
72- // return this.timeout !== null;
73- // }
74-
75- // cancel(): void {
76- // this.cancelTimeout();
77-
78- // if (this.completionPromise) {
79- // this.doReject(Error('Canceled'));
80- // this.completionPromise = null;
81- // }
82- // }
83-
8465 private cancelTimeout ( ) : void {
8566 if ( this . timeout !== null ) {
8667 clearTimeout ( this . timeout ) ;
8768 this . timeout = null ;
8869 }
8970 }
90-
91- // dispose(): void {
92- // this.cancelTimeout();
93- // }
94- }
71+ }
0 commit comments