Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides an abstraction over STM
, which can be used
with MonadConc
.
- class (Applicative m, Monad m, MonadCatch m, MonadThrow m) => MonadSTM m where
Documentation
class (Applicative m, Monad m, MonadCatch m, MonadThrow m) => MonadSTM m where Source
MonadSTM
is an abstraction over STM
.
This class does not provide any way to run transactions, rather
each MonadConc
has an associated MonadSTM
from which it can
atomically run a transaction.
A minimal implementation consists of retry
, orElse
, newCTVar
,
readCTVar
, and writeCTVar
.
The mutable reference type. These behave like TVar
s, in that
they always contain a value and updates are non-blocking and
synchronised.
Retry execution of this transaction because it has seen values
in CTVar
s that it shouldn't have. This will result in the
thread running the transaction being blocked until any CTVar
s
referenced in it have been mutated.
orElse :: m a -> m a -> m a Source
Run the first transaction and, if it retry
s, run the second
instead. If the monad is an instance of
'Alternative'/'MonadPlus', orElse
should be the '(|)'/'mplus'
function.
Check whether a condition is true and, if not, call retry
.
check b = unless b retry
newCTVar :: a -> m (CTVar m a) Source
Create a new CTVar
containing the given value.
readCTVar :: CTVar m a -> m a Source
Return the current value stored in a CTVar
.
writeCTVar :: CTVar m a -> a -> m () Source
Write the supplied value into the CTVar
.
throwSTM :: Exception e => e -> m a Source
Throw an exception. This aborts the transaction and propagates the exception.
throwSTM = Control.Monad.Catch.throwM
catchSTM :: Exception e => m a -> (e -> m a) -> m a Source
Handling exceptions from throwSTM
.
catchSTM = Control.Monad.Catch.catch
MonadSTM STM | |
MonadSTM m => MonadSTM (ReaderT r m) | |
MonadSTM m => MonadSTM (StateT s m) | |
MonadSTM m => MonadSTM (StateT s m) | |
(MonadSTM m, Monoid w) => MonadSTM (WriterT w m) | |
(MonadSTM m, Monoid w) => MonadSTM (WriterT w m) | |
Monad n => MonadSTM (STMLike t n r) | |
(MonadSTM m, Monoid w) => MonadSTM (RWST r w s m) | |
(MonadSTM m, Monoid w) => MonadSTM (RWST r w s m) |