Skip to content

Commit

Permalink
Propagate operation results through node.js txnWrapper example
Browse files Browse the repository at this point in the history
Modifies the callback behavior of the node.js transaction wrapper
code to propogate up all arguments to the callback in the user
defined operation.

Current implementation would only propogate the errors up, and not
any data that the user wishes to have returned.
  • Loading branch information
taywrobel committed Jun 17, 2017
1 parent 8b7fcda commit 8f27145
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions _includes/app/txn-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ function txnWrapper(client, op, next) {
if (err) {
return handleError(err);
}
var opResults = arguments;

// If we reach this point, release and commit.
client.query('RELEASE SAVEPOINT cockroach_restart', function (err) {
if (err) {
return handleError(err);
}
released = true;
return done();
return done.apply(null, opResults);
});
});
},
Expand All @@ -57,7 +58,14 @@ function txnWrapper(client, op, next) {
next(err);
});
} else {
client.query('COMMIT', next);
var txnResults = arguments;
client.query('COMMIT', function(err) {
if (err) {
return next(err);
} else {
return next.apply(null, txnResults);
}
});
}
});
});
Expand Down

0 comments on commit 8f27145

Please sign in to comment.