Hello,
I'm afraid you can't do that (for good reasons I won't go into unless you ask).
Instead, you will need to structure things so that it is ok that it is
not a single transaction. The first thing to ask yourself is if it
really matters if the database changes between the query and the
update. I've found that sometimes I assume things need to be a single
transaction, and then realize they do not when I look closer.
If it does matter, then next thing to ask yourself is if you can
modify your approach so that it doesn't matter.
Assuming that is not possible and the update only makes sense if the
result of the query has not changed, you could do something like:
retry $ do
x <- query' acidStorage (SomeQuery ....)
y <- someReasoningThatNeedsIO x
update' acidStorage (SomeUpdate x y)
The idea is:
1. do the query
2. calculate the IO result
3. pass the calculated value and the original query value to the
update function
4. SomeUpdate checks that the query value has not changed. If it has,
the update fails, if it hasn't then the update is applied.
5. retry checks if the update passed or failed and retries if it failed
This is a bit like how STM works -- assume everything is going to be
ok, and if it isn't just start over and try again. (At least that's
how I think STM works.. it's been a while).
This assumes that it is ok to run the IO operation multiple times. It
assumes a couple other things too -- such as being able to confirm
that the two query results are the same.
I used to run into this type of situation more often, and somehow I
have changed my approach so that it doesn't really come up anymore.
But, I think that some retry operations might be a nice addition to
acid-state. We definitely can not allow IO in the update/query events
themselves. But, we could provide a bit more infrastructure to support
IO outside the update/query events.
It's a bit hard to provide a great solution without seeing your code.
If you want to discuss your code in more depth, we can try to figure
out a good solution, and then, if needed, add some extra helper
functions to acid-state.
- jeremy