Skip to content

Instantly share code, notes, and snippets.

@KidkArolis
Created October 1, 2014 21:18
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 KidkArolis/2a1df3b15948e4b54fe6 to your computer and use it in GitHub Desktop.
Save KidkArolis/2a1df3b15948e4b54fe6 to your computer and use it in GitHub Desktop.
function upload(stream, idOrPath, tag) {
var queries = new Array(global.parallelQueries);
var tx = db.begin();
when.map(queries, insert).catch(rollback);
tx.commit();
function insert(query) {
FileVersion.insert({index: i}).execWithin(tx, query);
}
function rollback () {
tx.rollback();
}
}
task upload(stream, idOrPath, tag) {
var queries = new Array(global.parallelQueries),
tx = db.begin();
catch (e) {
tx.rollback();
}
var ch = new Channel();
for (var i = 0, len = queries.length; i < len; ++i) {
FileVersion.insert({index: i}).execWithin(tx, ch.receive(i));
}
await ch.takeN(queries.length);
tx.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment