Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont call syncho callback more than once #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/stores/indexeddb_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fullproof.store = fullproof.store || {};
"use strict";

try {
fullproof.store.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
fullproof.store.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.mozIDBTransaction || window.msIDBTransaction || {};
fullproof.store.indexedDB = indexedDB || window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
fullproof.store.IDBTransaction = IDBTransaction || window.IDBTransaction || window.webkitIDBTransaction || window.mozIDBTransaction || window.msIDBTransaction || {};
fullproof.store.READWRITEMODE = fullproof.store.IDBTransaction.readwrite || fullproof.store.IDBTransaction.READ_WRITE || "readwrite";
} catch(e) {
fullproof.store.indexedDB = window.indexedDB;
Expand Down Expand Up @@ -402,4 +402,4 @@ fullproof.store = fullproof.store || {};
return this.stores[name];
};

})(window || {});
})(typeof window === 'undefined' ? {} : window);
2 changes: 1 addition & 1 deletion src/stores/websql_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,4 @@ fullproof.store = fullproof.store||{};
});
};

})(window || {});
})(typeof window === 'undefined' ? {} : window);
26 changes: 18 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ fullproof.ScoredEntry.prototype.toString = function () {


/**
* Creates a synchronization point. This function returns a function that collects
* calls to callback, then calls its callback argument with all the data collected.
* The synchronization point can trigger the final call to callback when it either
* receives a fixed number of calls (expected argument >= 1), or when it
* receives a false boolean value as argument (expected has to be either undefined or false)
* Creates a synchronization point. Return a function that collects
* results and calls its callback argument with the collected data.
* The synchronization point will trigger the callback when either (a) it
* receives a predetermined number of results (expected argument >= 1), or
* (b) it receives a false boolean value as argument (expected has to be
* either undefined or false).

* Note that the callback function will never be called more than once.

* @param {function} callback the function to call when the synchronization point is reached
* @param {number} expected defines the synchronization point. If this is a number, the synchronization is
Expand All @@ -90,13 +93,17 @@ fullproof.ScoredEntry.prototype.toString = function () {
fullproof.make_synchro_point = function (callback, expected, debug, thrown_if_false) {
var count = 0;
var results = [];
var callbackCalled = false;
return function (res) {
if (thrown_if_false !== undefined && res === false) {
throw thrown_if_false;
}
if (expected === false || expected === undefined) {
if (res === false) {
callback(results);
if (callbackCalled === false) {
callbackCalled = true;
callback(results);
}
} else {
results.push(res);
}
Expand All @@ -108,10 +115,13 @@ fullproof.make_synchro_point = function (callback, expected, debug, thrown_if_fa
console.log("synchro point " + (typeof debug == "string" ? debug + ": " : ": ") + count + " / " + expected);
}
if (count == expected) {
callback(results);
if (callbackCalled === false) {
callbackCalled = true;
callback(results);
}
}
}
}
};
};

fullproof.call_new_thread = function() {
Expand Down