不要怂,就是干,撸起袖子干!

Commit 613401a5 by overlookmotel

Refactor for readability

1 parent a915f859
Showing with 12 additions and 13 deletions
...@@ -979,19 +979,18 @@ class Sequelize { ...@@ -979,19 +979,18 @@ class Sequelize {
if (!autoCallback) return transaction.prepareEnvironment().return(transaction); if (!autoCallback) return transaction.prepareEnvironment().return(transaction);
// autoCallback provided // autoCallback provided
return Sequelize._clsRun(() => return Sequelize._clsRun(() => {
transaction.prepareEnvironment().then(() => return transaction.prepareEnvironment()
autoCallback(transaction) .then(() => autoCallback(transaction))
).tap(() => .tap(() => transaction.commit())
transaction.commit() .catch(err => {
).catch(err => // Rollback transaction if not already finished (commit, rollback, etc)
// Rollback transaction if not already finished (commit, rollback, etc) and reject with original error // and reject with original error (ignore any error in rollback)
Promise.try(() => { return Promise.try(() => {
// Rollback (ignore any error in rollback) if (!transaction.finished) return transaction.rollback().catch(function() {});
if (!transaction.finished) return transaction.rollback().catch(function() {}); }).throw(err);
}).throw(err) });
) });
);
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!