haskus-utils-1.5: Haskus utility modules

Safe HaskellSafe
LanguageHaskell2010

Haskus.Utils.STM.SnapVar

Contents

Description

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

Documentation

data SnapVar a Source #

A snapshot variable

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