From c6f12f4ebaedd7f43ce83c89d2d36883d8d4144e Mon Sep 17 00:00:00 2001 From: Khai Truong Date: Tue, 5 Nov 2024 11:44:15 +0700 Subject: [PATCH] await database update before running next task --- ext/js/pages/settings/dictionary-controller.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js index 8b082a9d6..c7408bf94 100644 --- a/ext/js/pages/settings/dictionary-controller.js +++ b/ext/js/pages/settings/dictionary-controller.js @@ -514,6 +514,8 @@ export class DictionaryController { this._dictionaryTaskQueue = []; /** @type {boolean} */ this._isTaskQueueRunning = false; + /** @type {(() => void) | null} */ + this._onDatabaseUpdateDone = null; } /** @type {import('./modal-controller.js').ModalController} */ @@ -744,6 +746,9 @@ export class DictionaryController { this._dictionaries = dictionaries; await this._updateEntries(); + if (this._onDatabaseUpdateDone) { + this._onDatabaseUpdateDone(); + } } /** */ @@ -1097,6 +1102,13 @@ export class DictionaryController { } else if (task.type === 'update') { await this._updateDictionary(task.dictionaryTitle, task.downloadUrl); } + // await database update done before running next task + /** @type {Promise} */ + const databaseUpdatePromise = new Promise((resolve) => { + this._onDatabaseUpdateDone = resolve; + }); + await databaseUpdatePromise; + this._onDatabaseUpdateDone = null; void this._dictionaryTaskQueue.shift(); } this._isTaskQueueRunning = false;