Skip to content

Commit

Permalink
await database update before running next task
Browse files Browse the repository at this point in the history
  • Loading branch information
khaitruong922 committed Nov 5, 2024
1 parent 7132f01 commit c6f12f4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down Expand Up @@ -744,6 +746,9 @@ export class DictionaryController {
this._dictionaries = dictionaries;

await this._updateEntries();
if (this._onDatabaseUpdateDone) {
this._onDatabaseUpdateDone();
}
}

/** */
Expand Down Expand Up @@ -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<void>} */
const databaseUpdatePromise = new Promise((resolve) => {
this._onDatabaseUpdateDone = resolve;
});
await databaseUpdatePromise;
this._onDatabaseUpdateDone = null;
void this._dictionaryTaskQueue.shift();
}
this._isTaskQueueRunning = false;
Expand Down

0 comments on commit c6f12f4

Please sign in to comment.