Implement transactions operating on async closures.#33
Merged
Conversation
Collaborator
Author
|
Usage of this PR is demonstrated in oxidecomputer/omicron#1621 |
Collaborator
Author
|
This PR is also inspired by https://github.com/weiznich/diesel_async/blob/acf3ed3a2d7017098f2eb834633839d75d7256c7/src/pg/mod.rs#L206-L211 , which is the interface used in the (currently still prototype) async interface proposed to Diesel. It's a goal of async-bb8-diesel to be fairly closely aligned with that crate, to make conversion to it easy as it gains more stability. |
smklein
added a commit
to oxidecomputer/omicron
that referenced
this pull request
Sep 12, 2022
This PR is dependent on oxidecomputer/async-bb8-diesel#33 , and acts as a demonstration of asynchronous transaction blocks. This PR should be a big step forward for eliminating "special-case synchronous code" to access the DB within transactions. Whenever someone reaches for an interactive transaction, we'd prefer: - Pipelined transactions (not fully implemented, does not cover cases where we read-then-write) - Sagas (for DB-only operations, this is technically wasteful if we could do the same calculations in SQL) - CTEs (this is generally the "ideal" solution, but bears the highest complexity) *however*, given that we are trying to strike a balance between correctness, speed, safety, and developer productivity, this PR provides a cheap way for the "fastest option" - just writing normal async code in rust - to remain async, and interoperate with the rest of the codebase easily.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #32
This provides an additional method to the
AsyncConnectiontrait:transaction_async.transaction_asyncacts similarly totransaction, but instead of operating on a closure (which expects to be synchronous),transaction_asynccan operate on an asynchronous block.