[Persistence] Tweak logic

Tweak approach for revision conflict detection; particularly,
use .reject instead of throw to avoid logging of the failure
unnecessarily. WTD-1033.
This commit is contained in:
Victor Woeltjen 2015-03-20 15:53:40 -07:00
parent d8e1f69b37
commit b604af2aa7
2 changed files with 11 additions and 9 deletions

View File

@ -78,11 +78,11 @@ define(
// Load the updated model, then reject the promise // Load the updated model, then reject the promise
return get(key).then(function (model) { return get(key).then(function (model) {
error.model = model; error.model = model;
throw error; return $q.reject(error);
}); });
} }
// Reject the promise // Reject the promise
throw error; return $q.reject(error);
} }
// Check the response to a create/update/delete request; // Check the response to a create/update/delete request;

View File

@ -34,16 +34,18 @@ define(
return Object.keys(queue).length === lastObservedSize; 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 // Persist all queued objects
function flush() { function flush() {
// Persist all queued objects // Persist all queued objects
flushPromise = handler.persist(queue, objects); flushPromise = handler.persist(queue, objects)
.then(clearFlushPromise, clearFlushPromise);
// When persisted, clear the active promise
flushPromise.then(function (value) {
flushPromise = undefined;
activeDefer.resolve(value);
});
// Reset queue, etc. // Reset queue, etc.
queue = {}; queue = {};