Description
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
Activity