Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Snapshotable STM variables
A SnapVar
is like a TVar
except that they have a context which can
enable a snapshot mode. When in snapshot mode, the current values are not
erased by writes. Instead each SnapVar can have 2 values: the value at the
time of the snapshot and its current value.
There can be only a single snapshot at a time. When the snapshot mode is exited, the variables only keep the current value alive, not the snapshot one.
Synopsis
- data SnapVar a
- data SnapContext
- newSnapContextIO :: MonadIO m => m SnapContext
- newSnapContext :: STM SnapContext
- newSnapVarIO :: MonadIO m => SnapContext -> a -> m (SnapVar a)
- newSnapVar :: SnapContext -> a -> STM (SnapVar a)
- writeSnapVar :: SnapVar a -> a -> STM ()
- writeSnapVarIO :: MonadIO m => SnapVar a -> a -> m ()
- readSnapVar :: SnapVar a -> STM a
- readSnapVarIO :: MonadIO m => SnapVar a -> m a
- modifySnapVar :: SnapVar a -> (a -> a) -> STM a
- modifySnapVarIO :: MonadIO m => SnapVar a -> (a -> a) -> m a
- withSnapshot :: MonadIO m => SnapContext -> m r -> m r
- readSnapshot :: SnapVar a -> STM a
- readSnapshotIO :: MonadIO m => SnapVar a -> m a
Documentation
data SnapContext Source #
Snapshot context
newSnapContextIO :: MonadIO m => m SnapContext Source #
Create a new snapshot context
newSnapContext :: STM SnapContext Source #
Create a new snapshot context
newSnapVarIO :: MonadIO m => SnapContext -> a -> m (SnapVar a) Source #
Create a new SnapVar
newSnapVar :: SnapContext -> a -> STM (SnapVar a) Source #
Create a new SnapVar
writeSnapVar :: SnapVar a -> a -> STM () Source #
Write a SnapVar
writeSnapVarIO :: MonadIO m => SnapVar a -> a -> m () Source #
Write a SnapVar
readSnapVar :: SnapVar a -> STM a Source #
Read a SnapVar
readSnapVarIO :: MonadIO m => SnapVar a -> m a Source #
Read a SnapVar
modifySnapVar :: SnapVar a -> (a -> a) -> STM a Source #
Modify a SnapVar
modifySnapVarIO :: MonadIO m => SnapVar a -> (a -> a) -> m a Source #
Modify a SnapVar
Snapshot
withSnapshot :: MonadIO m => SnapContext -> m r -> m r Source #
Use a snapshot
readSnapshot :: SnapVar a -> STM a Source #
Read the snapshot value of the variable.
Must be used in the context of a withSnapshot
readSnapshotIO :: MonadIO m => SnapVar a -> m a Source #
Read the snapshot value of the variable.
Must be used in the context of a withSnapshot