File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ export class AutoFetcher {
3
3
this . timeout = AutoFetcher . DEFAULT_TIMEOUT ;
4
4
this . active = true ;
5
5
this . timer = undefined ;
6
+ this . launchCounter = 0 ;
6
7
}
7
8
8
9
wait ( ms : number ) {
@@ -16,13 +17,21 @@ export class AutoFetcher {
16
17
return ;
17
18
}
18
19
20
+ const currentLaunch = this . launchCounter ;
21
+
19
22
await this . wait ( this . timeout ) ;
20
23
21
24
if ( this . active ) {
22
25
const startTs = Date . now ( ) ;
23
26
await request ( ) ;
24
27
const finishTs = Date . now ( ) ;
25
28
29
+ if ( currentLaunch !== this . launchCounter ) {
30
+ // autofetcher was restarted while request was in progress
31
+ // stop further fetches, we are in deprecated thread
32
+ return ;
33
+ }
34
+
26
35
const responseTime = finishTs - startTs ;
27
36
const nextTimeout =
28
37
responseTime > AutoFetcher . MIN_TIMEOUT ? responseTime : AutoFetcher . MIN_TIMEOUT ;
@@ -40,6 +49,7 @@ export class AutoFetcher {
40
49
this . active = false ;
41
50
}
42
51
start ( ) {
52
+ this . launchCounter ++ ;
43
53
this . active = true ;
44
54
}
45
55
@@ -48,4 +58,5 @@ export class AutoFetcher {
48
58
timeout : number ;
49
59
active : boolean ;
50
60
timer : undefined | ReturnType < typeof setTimeout > ;
61
+ launchCounter : number ;
51
62
}
You can’t perform that action at this time.
0 commit comments