From 2709fde9a3ea159fe4e68bcba9cb32ecb5d4d796 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 Mar 2015 12:19:36 -0700 Subject: [PATCH] [Persistence] Resolve correct promise from queue Make sure that the correct promise is resolved when a persistence queue flush completes; some operations, like Save in Edit mode, wait on this promise, so it needs to resolve when persistence of that group is completed. WTD-1033. --- .../queue/src/PersistenceQueueImpl.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/platform/persistence/queue/src/PersistenceQueueImpl.js b/platform/persistence/queue/src/PersistenceQueueImpl.js index faee439e21..94393bf2e1 100644 --- a/platform/persistence/queue/src/PersistenceQueueImpl.js +++ b/platform/persistence/queue/src/PersistenceQueueImpl.js @@ -34,15 +34,22 @@ define( return Object.keys(queue).length === lastObservedSize; } - // Clear the active promise for a queue flush - function clearFlushPromise(value) { - flushPromise = undefined; - activeDefer.resolve(value); - return value; - } // Persist all queued objects function flush() { + // Get a local reference to the active promise; + // this will be replaced with a promise for the next round + // of persistence calls, so we want to make sure we clear + // the correct one when this flush completes. + var flushingDefer = activeDefer; + + // Clear the active promise for a queue flush + function clearFlushPromise(value) { + flushPromise = undefined; + flushingDefer.resolve(value); + return value; + } + // Persist all queued objects flushPromise = handler.persist(queue, objects) .then(clearFlushPromise, clearFlushPromise);