tbox-0.0.0: Transactional variables with IO hooksSource codeContentsIndex
Control.Concurrent.TBox
Portabilitynon-portable (requires STM)
Stabilityexperimental
MaintainerPeter Robinson <[email protected]>
Contents
TBox type class
Operations on a TBox
Description
An abstract interface for transactional variables with IO hooks.
Synopsis
class TBox t a where
writeSTM :: t a -> a -> AdvSTM ()
writeIO :: t a -> a -> IO ()
readSTM :: t a -> AdvSTM (Maybe a)
readIO :: t a -> IO (Maybe a)
deleteSTM :: t a -> AdvSTM ()
deleteIO :: t a -> IO ()
isDirty :: t a -> AdvSTM Bool
setDirty :: t a -> Bool -> AdvSTM ()
read :: TBox t a => t a -> AdvSTM (Maybe a)
write :: TBox t a => t a -> a -> AdvSTM ()
delete :: TBox t a => t a -> AdvSTM ()
isEmpty :: TBox t a => t a -> AdvSTM Bool
TBox type class
class TBox t a whereSource

An instance of TBox is a (Adv)STM variable that might contain a value of some type a. In contrast to a plain TVar, a TBox has IO hooks that are executed transparently on updates and reads. The functions of the type class shouldn't be exposed directly but should be used via the interface defined in the module TBox.Operations.

See the module TFile for a concrete instantiation.

Methods
writeSTM :: t a -> a -> AdvSTM ()Source
writeIO :: t a -> a -> IO ()Source
readSTM :: t a -> AdvSTM (Maybe a)Source
readIO :: t a -> IO (Maybe a)Source
Note: Might be executed multiple times for the same TBox in a single transaction. See unsafeRetryWith.
deleteSTM :: t a -> AdvSTM ()Source
deleteIO :: t a -> IO ()Source
isDirty :: t a -> AdvSTM BoolSource
If isDirty yields True, the readIO hook will be run on the next read.
setDirty :: t a -> Bool -> AdvSTM ()Source
show/hide Instances
Operations on a TBox
read :: TBox t a => t a -> AdvSTM (Maybe a)Source

If the TBox is dirty, this retries the transaction and rereads the content using readIO in a separate thread. Otherwise it simply returns the result of readSTM.

Note: Depending on the implementation, careless use of setDirty and read in the same transaction might lead to nonterminating retry loops.

write :: TBox t a => t a -> a -> AdvSTM ()Source
Writes the new content.
delete :: TBox t a => t a -> AdvSTM ()Source
Deletes the content.
isEmpty :: TBox t a => t a -> AdvSTM BoolSource
Returns True iff the TBox is empty.
Produced by Haddock version 2.4.2