File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change 1- export interface SimpleDebounce {
1+ import { Disposable } from 'vscode' ;
2+
3+ export interface SimpleDebounce extends Disposable {
24 trigger ( ) : void ;
35}
46
5- class SimpleDebounceImpl {
7+ class SimpleDebounceImpl extends Disposable {
68 private timeout : NodeJS . Timeout | undefined ;
79
8- constructor ( private readonly ms : number , private readonly callback : ( ) => void ) { }
10+ constructor ( private readonly ms : number , private readonly callback : ( ) => void ) {
11+ super ( ( ) => {
12+ if ( this . timeout ) {
13+ clearTimeout ( this . timeout ) ;
14+ this . timeout = undefined ;
15+ }
16+ } ) ;
17+ }
918
1019 public trigger ( ) {
1120 if ( this . timeout ) {
@@ -15,6 +24,12 @@ class SimpleDebounceImpl {
1524 this . callback ( ) ;
1625 } , this . ms ) ;
1726 }
27+
28+ public dispose ( ) {
29+ if ( this . timeout ) {
30+ clearTimeout ( this . timeout ) ;
31+ }
32+ }
1833}
1934
2035export function createSimpleDebounce ( ms : number , callback : ( ) => void ) : SimpleDebounce {
You can’t perform that action at this time.
0 commit comments