commit 7271fdf6b72d78329273229f9602806ad7b13b78
parent 86b94ae713dc600927ac3949c07bdb83e063ea13
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 4 May 2018 19:53:54 -0400
Add Zotero.Sync.Runner.delayIndefinite()
Delays syncing until the returned function is run
Diffstat:
1 file changed, 31 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js
@@ -70,6 +70,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
var _enabled = false;
var _autoSyncTimer;
var _delaySyncUntil;
+ var _delayPromises = [];
var _firstInSession = true;
var _syncInProgress = false;
var _stopping = false;
@@ -148,6 +149,21 @@ Zotero.Sync.Runner_Module = function (options = {}) {
yield Zotero.Promise.delay(delay);
}
+ // If paused, wait until we're done
+ while (true) {
+ if (_delayPromises.some(p => p.isPending())) {
+ this.setSyncStatus(Zotero.getString('sync.status.waiting'));
+ Zotero.debug("Syncing is paused -- waiting to sync");
+ yield Zotero.Promise.all(_delayPromises);
+ // If more were added, continue
+ if (_delayPromises.some(p => p.isPending())) {
+ continue;
+ }
+ _delayPromises = [];
+ }
+ break;
+ }
+
// purgeDataObjects() starts a transaction, so if there's an active one then show a
// nice message and wait until there's not. Another transaction could still start
// before purgeDataObjects() and result in a wait timeout, but this should reduce the
@@ -959,6 +975,21 @@ Zotero.Sync.Runner_Module = function (options = {}) {
/**
+ * Delay syncs until the returned function is called
+ *
+ * @return {Function} - Resolve function
+ */
+ this.delayIndefinite = function () {
+ var resolve;
+ var promise = new Zotero.Promise(function () {
+ resolve = arguments[0];
+ });
+ _delayPromises.push(promise);
+ return resolve;
+ };
+
+
+ /**
* Trigger updating of the main sync icon, the sync error icon, and
* library-specific sync error icons across all windows
*/