blocking-transactions-0.1.0.4: Composable, blocking transactions.

BlockingTransactions.BlockingTransactions

Contents

Description

Composable blocking transactions, based on the blog post: http://blog.downstairspeople.org/2010/06/06/composable-blocking-transactions/

Synopsis

Transactional Variables

data BVar a Source

A transactional variable with a blocking implementation.

Instances

Eq (BVar a) 
Ord (BVar a) 

newBVar :: a -> IO (BVar a)Source

Construct a new transactional variable.

peekBVar :: BVar a -> IO aSource

Observe the contents of a transactional variable.

pokeBVar :: BVar a -> a -> IO ()Source

One-off write to a transactional variable.

modifyBVar :: BVar a -> (a -> (a, b)) -> IO bSource

Perform a transaction using only a single variable.

Blocking Transaction Monad

runBTM :: (forall e. BTM e (Value e a)) -> IO aSource

Commit a blocking transaction.

data BTM e a Source

The blocking transaction monad.

Instances

data Value e a Source

An opaque value. It can be modified and combined with other opaque values, but not observed.

The type variable e binds the value to the monadic context in which it occurs, (this is identical to the runST existential type trick).

Instances

when :: Value e Bool -> BTM e (Value e ()) -> BTM e (Value e ())Source

Flow control. Skip the critical section if the predicate is false.

unless :: Value e Bool -> BTM e (Value e ()) -> BTM e (Value e ())Source

Flow control. Skip the critical section if the predicate is true.

readBVar :: BVar a -> BTM e (Value e a)Source

Read from a variable.

writeBVar :: BVar a -> Value e a -> BTM e (Value e ())Source

Write to a variable.

retry :: BTM e (Value e ())Source

Electively retry. This will restore all variables to their state before the transaction began, and listen for a change to any variable in the working set before trying the transaction again.

Blocking Transaction Arrow

runBTA :: BTA a b -> a -> IO bSource

data BTA a b Source

The blocking transaction arrow. The semantics are identical to the equivalent operations on the monadic interface.