Skip to content
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

[Refactor] Represent transactions in a separate typestate + contextmanager #209

Open
mitchhentges opened this issue Jul 5, 2019 · 0 comments

Comments

@mitchhentges
Copy link
Contributor

Instead of having a mutable EditService and having checks before operation to assert state (which is what we're doing relatively ergonomically with this @transaction_required annotation), we could utilize typestates. So, you'll call a function to start the transaction, and you'll receive a transaction object that can perform all the operations (and commit at the end).

This way, it's easier to use this API, since you don't have functions on your objects that have implicit requirements - you physically can't call transaction functions until you've started the transaction. Additionally, there's less room for errors when changing the API, such as forgetting the @transaction_required annotation, since required resources (like edit_id) would sit in the transaction object.

Additionally, by making the transaction object work with a context manager, we can have automatic committing when exiting a with ... block, which would make this even better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant