Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function poll() {
pollHandle = null;
var currentInstance = mySyncNode.id;
Dexie.vip(function() { // VIP ourselves. Otherwise we might not be able to consume intercomm messages from master node before database has finished opening. This would make DB stall forever. Cannot rely on storage-event since it may not always work in some browsers of different processes.
readChanges(Observable.latestRevision[db.name]).then(cleanup).then(consumeIntercommMessages).finally(function() {
// Poll again in given interval:
if (mySyncNode && mySyncNode.id === currentInstance) {
pollHandle = setTimeout(poll, LOCAL_POLL);
}
});
});
}
function onSuicide(dbname, nodeID) {
if (dbname === db.name && !Observable.wereTheOneDying) {
// Make sure it's dead indeed. Second bullet. Why? Because it has marked itself for deletion in the onbeforeunload event, which is fired just before window dies.
// It's own call to put() may have been cancelled.
// Note also that in IE, this event may be called twice, but that doesnt harm!
Dexie.vip(function() {
db._syncNodes.update(nodeID, { deleteTimeStamp: 1, lastHeartBeat: 0 }).then(cleanup);
});
}
}
PersistedContext.prototype.save = function () {
// Store this instance in the syncContext property of the node it belongs to.
return Dexie.vip(function () {
return node.save();
});
};
function onSuicide(dbname, nodeID) {
if (dbname === db.name && !Observable.wereTheOneDying) {
// Make sure it's dead indeed. Second bullet. Why? Because it has marked itself for deletion in the onbeforeunload event, which is fired just before window dies.
// It's own call to put() may have been cancelled.
// Note also that in IE, this event may be called twice, but that doesnt harm!
Dexie.vip(function() {
db._syncNodes.update(nodeID, { deleteTimeStamp: 1, lastHeartBeat: 0 }).then(cleanup);
});
}
}
function poll() {
pollHandle = null;
var currentInstance = mySyncNode.id;
Dexie.vip(function() { // VIP ourselves. Otherwise we might not be able to consume intercomm messages from master node before database has finished opening. This would make DB stall forever. Cannot rely on storage-event since it may not always work in some browsers of different processes.
readChanges(Observable.latestRevision[db.name]).then(cleanup).then(consumeIntercommMessages)
.catch('DatabaseClosedError', e=>{
// Handle database closed error gracefully while reading changes.
// Don't signal 'unhandledrejection'.
// Even though we intercept the close() method, it might be called when in the middle of
// reading changes and then that flow will cancel with DatabaseClosedError.
})
.finally(function() {
// Poll again in given interval:
if (mySyncNode && mySyncNode.id === currentInstance) {
pollHandle = setTimeout(poll, LOCAL_POLL);
}
});
});
}
function poll() {
pollHandle = null;
var currentInstance = mySyncNode.id;
Dexie.vip(function () {
// VIP ourselves. Otherwise we might not be able to consume intercomm messages from master node before database has finished opening. This would make DB stall forever. Cannot rely on storage-event since it may not always work in some browsers of different processes.
readChanges(Observable.latestRevision[db.name]).then(cleanup).then(consumeIntercommMessages).finally(function () {
// Poll again in given interval:
if (mySyncNode && mySyncNode.id === currentInstance) {
pollHandle = setTimeout(poll, LOCAL_POLL);
}
});
});
}
save() {
// Store this instance in the syncContext property of the node it belongs to.
return Dexie.vip(() => {
return node.save();
});
}
}
function onLatestRevisionIncremented(dbname, latestRevision) {
if (dbname === db.name) {
if (handledRevision >= latestRevision) return; // Make sure to only run once per revision. (Workaround for IE triggering storage event on same window)
handledRevision = latestRevision;
Dexie.vip(function() {
readChanges(latestRevision).catch('DatabaseClosedError', e=>{
// Handle database closed error gracefully while reading changes.
// Don't trigger unhandledrejection
// Even though we intercept the close() method, it might be called when in the middle of
// reading changes and then that flow will cancel with DatabaseClosedError.
});
});
}
}
function onLatestRevisionIncremented(dbname, latestRevision) {
if (dbname === db.name) {
if (handledRevision >= latestRevision) return; // Make sure to only run once per revision. (Workaround for IE triggering storage event on same window)
handledRevision = latestRevision;
Dexie.vip(function() {
readChanges(latestRevision);
});
}
}
context.ongoingOperation = Dexie.ignoreTransaction(function () {
return Dexie.vip(function () {
return fn();
});
}).finally(()=> {
delete context.ongoingOperation;