| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.DejaFu.STM
- data STMLike t n r a
- type STMST t a = STMLike t (ST t) (STRef t) a
- type STMIO t a = STMLike t IO IORef a
- data Result a
- runTransaction :: (forall t. STMST t a) -> Result a
- runTransactionST :: STMST t a -> CTVarId -> ST t (Result a, CTVarId)
- runTransactionIO :: STMIO t a -> CTVarId -> IO (Result a, CTVarId)
- retry :: Monad n => STMLike t n r a
- orElse :: Monad n => STMLike t n r a -> STMLike t n r a -> STMLike t n r a
- check :: Monad n => Bool -> STMLike t n r ()
- throwSTM :: Exception e => e -> STMLike t n r a
- catchSTM :: Exception e => STMLike t n r a -> (e -> STMLike t n r a) -> STMLike t n r a
- data CTVar t r a
- type CTVarId = Int
- newCTVar :: Monad n => a -> STMLike t n r (CTVar t r a)
- readCTVar :: Monad n => CTVar t r a -> STMLike t n r a
- writeCTVar :: Monad n => CTVar t r a -> a -> STMLike t n r ()
The STMLike Monad
The MonadSTM implementation, it encapsulates a single atomic
transaction. The environment, that is, the collection of defined
CTVars is implicit, there is no list of them, they exist purely
as references. This makes the types simpler, but means you can't
really get an aggregate of them (if you ever wanted to for some
reason).
The result of an STM transaction, along with which CTVars it
touched whilst executing.
Constructors
| Success [CTVarId] [CTVarId] a | The transaction completed successfully, reading the first list
|
| Retry [CTVarId] | The transaction aborted by calling |
| Exception SomeException | The transaction aborted by throwing an exception. |
runTransaction :: (forall t. STMST t a) -> Result a Source
Run a transaction in the ST monad, starting from a clean
environment, and discarding the environment afterwards. This is
suitable for testing individual transactions, but not for composing
multiple ones.
Software Transactional Memory
orElse :: Monad n => STMLike t n r a -> STMLike t n r a -> STMLike t n r a Source
Run the first transaction and, if it retrys,
check :: Monad n => Bool -> STMLike t n r () Source
Check whether a condition is true and, if not, call retry.
throwSTM :: Exception e => e -> STMLike t n r a Source
Throw an exception. This aborts the transaction and propagates the exception.
catchSTM :: Exception e => STMLike t n r a -> (e -> STMLike t n r a) -> STMLike t n r a Source
Handling exceptions from throwSTM.
CTVars
The unique ID of a CTVar. Only meaningful within a single
concurrent computation.
newCTVar :: Monad n => a -> STMLike t n r (CTVar t r a) Source
Create a new CTVar containing the given value.