|
Takes an IO action that will be executed iff the transaction commits.
- When a TVar was modified in a transaction and this transaction commits,
this update remains invisible to other threads until the corresponding
onCommit action was run.
- If the onCommit action throws an exception, the original value of
the TVars will be restored.
- Accessing a modified TVar within the onCommit action will cause a
Deadlock exception to be thrown.
As a general rule, onCommit should
only be used for "real" (i.e. without atomic blocks) IO actions and is certainly
not the right place to fiddle with TVars. For example, if you wanted to
write a TVar value to a file on commit, you could write:
tvar <- newTVarIO "bla"
atomically $ do
x <- readTVar tvar
onCommit (writeFile "myfile" x)
|
|
|
Retries the transaction and uses unsafeIOToSTM to fork off a
thread that runs the given IO action. Since a transaction might be rerun
several times by the runtime system, it is your responsibility to
ensure that the IO-action is idempotent and releases all acquired locks.
|
|
orElse :: m a -> m a -> m a | Source |
|
See orElse
|
|
|
See retry
|
|
|
See check
|
|
|
See alwaysSucceeds
|
|
|
See always
|
|
|
See catchSTM
|
|
|
Lifts STM actions to MonadAdvSTM.
|
|
|
Reads a value from a TVar. Blocks until the IO onCommit action(s) of
the corresponding transaction are complete.
See onCommit for a more detailed description of this behaviour.
|
|
|
Writes a value to a TVar. Blocks until the onCommit IO-action(s) are
complete. See onCommit for details.
|
|
|
See newTVar
|