Skip to content

Instantly share code, notes, and snippets.

@chrisvest
Last active December 29, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvest/7646523 to your computer and use it in GitHub Desktop.
Save chrisvest/7646523 to your computer and use it in GitHub Desktop.
var tx;
try {
tx = database.beginTx();
var homer = database.createNode();
var marge = database.createNode();
var wedding = inTransaction(tx, function() {
var married = homer.createRelationshipTo(marge, 'MARRIED_WITH');
tx.success();
});
setTimeout(wedding, 3000);
}
finally {
tx.finish();
}
// where
function inTransaction(tx, f) {
tx.incrementReferenceCount();
return function() {
tx.resume(); // rebinds the transaction to the current thread
try {
f();
}
finally {
tx.finish();
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment