Fix overlapping version checks (#716)

This commit is contained in:
toasted-nutbread 2020-08-09 13:17:15 -04:00 committed by GitHub
parent d856e4caac
commit b3eb2cb1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ class AnkiConnect {
this._server = server; this._server = server;
this._localVersion = 2; this._localVersion = 2;
this._remoteVersion = 0; this._remoteVersion = 0;
this._versionCheckPromise = null;
} }
setServer(server) { setServer(server) {
@ -98,7 +99,12 @@ class AnkiConnect {
async _checkVersion() { async _checkVersion() {
if (this._remoteVersion < this._localVersion) { 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) { if (this._remoteVersion < this._localVersion) {
throw new Error('Extension and plugin versions incompatible'); throw new Error('Extension and plugin versions incompatible');
} }