-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add setAutoCommit method to the Transaction class #1459
base: master
Are you sure you want to change the base?
Conversation
thisPtr->commitCallback_(true); | ||
} | ||
}, | ||
[thisPtr](const std::exception_ptr &) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the last place we used thisPtr
. Can move move it to avid a copy?
commitCb = std::move(commitCallback_), | ||
autoCommit = autoCommit_]() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UB if the user manually commits then auto commit happens. Could the following happen?
auto t = db->newTransactionCoro();
...
t->commit();
// now `t` destructs. Calls auto commit. We try to move an already moved variable.
{ | ||
commitCb(true); | ||
} | ||
}, | ||
[commitCb](const std::exception_ptr &ePtr) { | ||
[commitCb, autoCommit](const std::exception_ptr &ePtr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is the last time we use commitCb
. We can move it instead of making a copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the arguments evaluated in left-to-right order? If not, we can not use move.
LOG_TRACE << "Transaction committed!"; | ||
if (commitCb) | ||
if (autoCommit && commitCb) | ||
{ | ||
commitCb(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be commitCb(autoCommit)
?
same in execption callback
I prefer not using this commitCb. It's confusing.
#1386 #1428