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 {
33 this . timeout = AutoFetcher . DEFAULT_TIMEOUT ;
44 this . active = true ;
55 this . timer = undefined ;
6+ this . launchCounter = 0 ;
67 }
78
89 wait ( ms : number ) {
@@ -16,13 +17,21 @@ export class AutoFetcher {
1617 return ;
1718 }
1819
20+ const currentLaunch = this . launchCounter ;
21+
1922 await this . wait ( this . timeout ) ;
2023
2124 if ( this . active ) {
2225 const startTs = Date . now ( ) ;
2326 await request ( ) ;
2427 const finishTs = Date . now ( ) ;
2528
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+
2635 const responseTime = finishTs - startTs ;
2736 const nextTimeout =
2837 responseTime > AutoFetcher . MIN_TIMEOUT ? responseTime : AutoFetcher . MIN_TIMEOUT ;
@@ -40,6 +49,7 @@ export class AutoFetcher {
4049 this . active = false ;
4150 }
4251 start ( ) {
52+ this . launchCounter ++ ;
4353 this . active = true ;
4454 }
4555
@@ -48,4 +58,5 @@ export class AutoFetcher {
4858 timeout : number ;
4959 active : boolean ;
5060 timer : undefined | ReturnType < typeof setTimeout > ;
61+ launchCounter : number ;
5162}
You can’t perform that action at this time.
0 commit comments