diff --git a/chrome/content/zotero/xpcom/storage/storageEngine.js b/chrome/content/zotero/xpcom/storage/storageEngine.js index 4804abc92d..224998ced8 100644 --- a/chrome/content/zotero/xpcom/storage/storageEngine.js +++ b/chrome/content/zotero/xpcom/storage/storageEngine.js @@ -227,11 +227,11 @@ Zotero.Sync.Storage.Engine.prototype.start = async function () { let failed = 0; for (let p of results) { - if (p.isFulfilled()) { + try { + await p; succeeded++; } - else if (!p.isPending()) { - let e = p.reason(); + catch (e) { if (e instanceof Zotero.HTTP.CancelledException) { Zotero.debug(`File ${type} sync cancelled for ${this.library.name} ` + `(${succeeded} succeeded, ${failed} failed)`); diff --git a/resource/concurrentCaller.mjs b/resource/concurrentCaller.mjs index 3d4a11cb70..d060a01f70 100644 --- a/resource/concurrentCaller.mjs +++ b/resource/concurrentCaller.mjs @@ -115,19 +115,21 @@ ConcurrentCaller.prototype.add = function (func) { if (Array.isArray(func)) { let promises = []; for (let i = 0; i < func.length; i++) { - promises.push(this.start(func[i]).reflect()); + promises.push(this.start(func[i])); } - return Promise.all(promises); + return Promise.allSettled(promises).then(() => promises); } - if (!this._deferred || !this._deferred.promise.isPending()) { + if (!this._deferred) { this._deferred = Promise.defer(); + let onResolve = () => this._deferred = null; + this._deferred.promise.then(onResolve, onResolve); } var deferred = Promise.defer(); this._queue.push({ - func: Promise.method(func), - deferred: deferred + func, + deferred }); return deferred.promise; } @@ -151,7 +153,7 @@ ConcurrentCaller.prototype.start = function (func) { /** * Start processing if not already running and wait for all tasks to complete * - * @return {Promise[]} - An array of promises for all currently queued tasks + * @return {Promise} - An array of promises for all currently queued tasks */ ConcurrentCaller.prototype.runAll = function () { // If nothing queued, return immediately @@ -163,7 +165,7 @@ ConcurrentCaller.prototype.runAll = function () { var run = this._processNext(); } while (run); - return this._deferred.promise.return(promises); + return this._deferred.promise.then(() => promises); }