File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ async function rutine(ext: Ext, args?: string[]) {
110
110
111
111
export default async function analyse ( ext : Ext , ms ?: number , args ?: string [ ] ) {
112
112
await stopAnalyse ( ext ) ;
113
- ext . store . analyse . timeout ( async ( ) => {
113
+ ext . store . analyse . timeout . run ( async ( ) => {
114
114
await rutine ( ext , args ) ;
115
115
} , ms ?? ext . settings . analysedDelay ) ;
116
116
}
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ export class Ext<
211
211
tag : `event:${ eventName } ` ,
212
212
message : path ,
213
213
} ) ;
214
- this . store . reactivate . timeout ( ( ) => this . reactivate ( ) ) ;
214
+ this . store . reactivate . timeout . run ( ( ) => this . reactivate ( ) ) ;
215
215
}
216
216
) ;
217
217
Original file line number Diff line number Diff line change 1
- export type DelayedTimeout = ( cb : ( ) => unknown , ms ?: number ) => void ;
1
+ export type DelayedTimeout = {
2
+ readonly running : boolean ;
3
+ readonly pending : boolean ;
4
+ run : ( cb : ( ) => unknown , ms ?: number ) => void ;
5
+ } ;
2
6
3
7
export function createDelayedTimeout ( defaultsMs ?: number ) {
4
8
let timeout : NodeJS . Timeout | undefined ;
5
- return ( cb : ( ) => unknown , ms = defaultsMs ) => {
6
- if ( timeout ) clearTimeout ( timeout ) ;
7
- timeout = setTimeout ( cb , ms ) ;
9
+ let running = false ;
10
+ let pending = false ;
11
+ return {
12
+ get pending ( ) {
13
+ return pending ;
14
+ } ,
15
+ get running ( ) {
16
+ return running ;
17
+ } ,
18
+ run : ( cb : ( ) => unknown , ms = defaultsMs ) => {
19
+ pending = true ;
20
+ if ( timeout ) clearTimeout ( timeout ) ;
21
+ timeout = setTimeout ( async ( ) => {
22
+ running = true ;
23
+ try {
24
+ await cb ( ) ;
25
+ } finally {
26
+ running = pending = false ;
27
+ }
28
+ } , ms ) ;
29
+ } ,
8
30
} ;
9
31
}
You can’t perform that action at this time.
0 commit comments