[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.
This commit is contained in:
Victor Woeltjen 2015-03-24 12:19:36 -07:00
parent 821cc65d6f
commit 2709fde9a3

View File

@ -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);