Commit 2d5a5f89 authored by Sven Franck's avatar Sven Franck

fixed timeout because of errors not being caught in sequence

parent 24b9e1e7
...@@ -51,14 +51,16 @@ ...@@ -51,14 +51,16 @@
* @return {Object} clones object * @return {Object} clones object
*/ */
function cleanClone (obj) { function cleanClone (obj) {
// NOTE: polyfill needed for IE8- var prop, r = {};
var r = Object.create(obj);
if (r._missing) { for (prop in obj) {
delete r._missing; if (obj.hasOwnProperty(prop)) {
} if (prop.charCodeAt(0) !== 95 || prop === "_id") {
if (r._conflict_list) { r[prop] = obj[prop];
delete r._conflict_list; }
}
} }
return r; return r;
}; };
...@@ -242,14 +244,14 @@ ...@@ -242,14 +244,14 @@
promise_list = promise_list.slice(); promise_list = promise_list.slice();
return new Promise(function (resolve, reject, notify) { return new Promise(function (resolve, reject, notify) {
var index, doc, trace, version_list, count, error_count, tag; var index, trace, conflict_list, count, error_count, tag, doc;
version_list = [];
count = 0; count = 0;
error_count = 0; error_count = 0;
conflict_list = [];
tag = function (reply) { tag = function (reply) {
if (version_list.length) { if (conflict_list.length) {
reply._conflict_list = version_list; reply._conflict_list = conflict_list;
} }
if (error_count) { if (error_count) {
reply._missing = true; reply._missing = true;
...@@ -259,19 +261,16 @@ ...@@ -259,19 +261,16 @@
function resolver(answer) { function resolver(answer) {
if (trace === undefined) { if (trace === undefined) {
trace = checksum(answer);
doc = answer; doc = answer;
trace = checksum(cleanClone(answer.data));
} else { } else {
if (trace !== checksum(answer)) { if (trace !== checksum(cleanClone(answer.data))) {
if (version.list.length === 0) { conflict_list.push(cleanClone(answer.data));
version_list.push(doc);
}
version_list.push(answer);
} }
} }
count += 1; count += 1;
if (count === length) { if (count === length) {
return resolve(tag(doc)); return resolve(tag(answer));
} }
} }
function rejecter(answer) { function rejecter(answer) {
...@@ -292,7 +291,6 @@ ...@@ -292,7 +291,6 @@
}); });
}; };
} }
for (index = 0; index < length; index += 1) { for (index = 0; index < length; index += 1) {
promise_list[index].then(resolver, rejecter, notifier(index)); promise_list[index].then(resolver, rejecter, notifier(index));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment