summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-04-20 11:05:20 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-04-21 08:12:39 +0200
commit0ed2aa6e8a5be20bbc5b252968163eeace7d872d (patch)
treec6f568d006e297ec5ee866b59275af052347765f /gui/src
parent57e0a224d4769a2d92f6d1e3a3628596636c05e1 (diff)
downloadmullvadvpn-0ed2aa6e8a5be20bbc5b252968163eeace7d872d.tar.xz
mullvadvpn-0ed2aa6e8a5be20bbc5b252968163eeace7d872d.zip
Prevent clear scheduled fetch when performing new fetch
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/main/account-data-cache.ts18
1 files changed, 13 insertions, 5 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts
index 7db2c05ca8..034ec5b379 100644
--- a/gui/src/main/account-data-cache.ts
+++ b/gui/src/main/account-data-cache.ts
@@ -41,6 +41,10 @@ export default class AccountDataCache {
this.watchers.push(watcher);
}
+ this.clearFetchRetryTimeout();
+ // If a scheduled retry is cancelled the fetchAttempt shouldn't be increased.
+ this.fetchAttempt = Math.max(0, this.fetchAttempt - 1);
+
consumePromise(this.performFetch(accountToken));
} else if (watcher) {
watcher.onFinish();
@@ -48,11 +52,8 @@ export default class AccountDataCache {
}
public invalidate() {
- if (this.fetchRetryTimeout) {
- clearTimeout(this.fetchRetryTimeout);
- this.fetchRetryTimeout = undefined;
- this.fetchAttempt = 0;
- }
+ this.clearFetchRetryTimeout();
+ this.fetchAttempt = 0;
this.expiresAt = undefined;
this.updateHandler();
@@ -61,6 +62,13 @@ export default class AccountDataCache {
});
}
+ private clearFetchRetryTimeout() {
+ if (this.fetchRetryTimeout) {
+ clearTimeout(this.fetchRetryTimeout);
+ this.fetchRetryTimeout = undefined;
+ }
+ }
+
private setValue(value: IAccountData) {
this.expiresAt = new Date(Date.now() + 60 * 1000); // 60s expiration
this.updateHandler(value);