Skip to content

How to work with transaction using Aff? #1211

Answered by louthy
ychinghin asked this question in Q&A
Discussion options

You must be logged in to vote

That's actually a reasonable approach, if you think about it, you must Run(), because it's a resource that has pre-and-post effects - so the lazy Aff must be forced to evaluate. Wrapping it up like this is a good approach, it hides the Run and embelishes the Aff with transactional support.

If you wrap up the transaction part into an extension method, you can do something like aff.WithTransaction(context) to run it. Another thing: you should probably wrap up everything inside an AffMaybe(() => ...) rather than just the result. The effect you'll have here is to create a memoised result (which may be what you want, I dunno). By wrapping everything you get a re-runnable Aff.

I'd refactor it l…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ychinghin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants