From b3eb2cb1ef9fd28ea2dadb9eda8568a3b6958e9c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 9 Aug 2020 13:17:15 -0400 Subject: [PATCH] Fix overlapping version checks (#716) --- ext/bg/js/anki.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index a72dff2a..29ae5f0b 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -21,6 +21,7 @@ class AnkiConnect { this._server = server; this._localVersion = 2; this._remoteVersion = 0; + this._versionCheckPromise = null; } setServer(server) { @@ -98,7 +99,12 @@ class AnkiConnect { async _checkVersion() { if (this._remoteVersion < this._localVersion) { - this._remoteVersion = await this._invoke('version'); + if (this._versionCheckPromise === null) { + const promise = this._invoke('version'); + promise.finally(() => { this._versionCheckPromise = null; }); + this._versionCheckPromise = promise; + } + this._remoteVersion = await this._versionCheckPromise; if (this._remoteVersion < this._localVersion) { throw new Error('Extension and plugin versions incompatible'); }