This issue follows from the GitHub discussion here: https://github.com/mongodb/mongo-go-driver/pull/161.
Basically, I believe that we should provide a transaction API similar to `database/sql` for these reasons:
The callback API is unfortunate to work with in real-world code. Even if there are concurrency problems, I would much prefer this as an option with clear documentation than be forced to use callbacks.
Within the callback, it's more difficult to return the outer function or initialize outer variables. This leads to variable shadowing, interface type assertions, and duplicated error handling. All of which significantly increase the volume of code, and the probability of bugs.
Lastly, Go packages should take inspiration from the stdlib as much as possible for a consistent user experience. The Go authors decided to avoid the callback API in database/sql.
- is duplicated by
-
GODRIVER-1523 Expose SessionContext of transactions
-
- Closed
-