mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 16:14:01 +08:00
fix(sync-worker): Don't call _determineWorkerPool() twice
A race condition on bootup was causing us to sometimes start two delta sync workers for the same account.
This commit is contained in:
parent
baa9d7d363
commit
b1aeefe433
1 changed files with 8 additions and 0 deletions
|
@ -21,6 +21,12 @@ export default class NylasSyncWorkerPool {
|
|||
}
|
||||
|
||||
_determineWorkerPool() {
|
||||
// we need a function lock on this because on bootup, many legitimate
|
||||
// events coming in may result in this function being called multiple times
|
||||
// in quick succession, which can cause us to start multiple syncs for the
|
||||
// same account
|
||||
if (this._isBuildingWorkers) return;
|
||||
this._isBuildingWorkers = true;
|
||||
if (NylasEnv.inSpecMode()) { return; }
|
||||
const origWorkers = this._workers;
|
||||
const currentWorkers = []
|
||||
|
@ -40,6 +46,8 @@ export default class NylasSyncWorkerPool {
|
|||
const oldWorkers = _.difference(origWorkers, currentWorkers);
|
||||
for (const worker of oldWorkers) { worker.cleanup() }
|
||||
this._workers = currentWorkers;
|
||||
}).finally(() => {
|
||||
this._isBuildingWorkers = false;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue