Last active
December 29, 2015 08:49
-
-
Save chrisvest/7646523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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