strict-checked-vars
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Class.MonadSTM.Strict.TVar.Checked

Description

This module corresponds to Control.Concurrent.STM.TVar in the stm package.

This module can be used as a drop-in replacement for Control.Concurrent.Class.MonadSTM.Strict.TVar, but not the other way around.

Synopsis

StrictTVar

type LazyTVar (m :: Type -> Type) = LazyTVar m Source #

data StrictTVar (m :: Type -> Type) a Source #

castStrictTVar :: forall (m :: Type -> Type) (n :: Type -> Type) a. LazyTVar m ~ LazyTVar n => StrictTVar m a -> StrictTVar n a Source #

fromLazyTVar :: forall (m :: Type -> Type) a. LazyTVar m a -> StrictTVar m a Source #

Create a StrictMVar from a LazyMVar

It is not guaranteed that the LazyTVar contains a value that is in WHNF, so there is no guarantee that the resulting StrictTVar contains a value that is in WHNF. This should be used with caution.

The resulting StrictTVar has a trivial invariant.

modifyTVar :: forall (m :: Type -> Type) a. MonadSTM m => StrictTVar m a -> (a -> a) -> STM m () Source #

newTVar :: forall (m :: Type -> Type) a. MonadSTM m => a -> STM m (StrictTVar m a) Source #

newTVarIO :: MonadSTM m => a -> m (StrictTVar m a) Source #

newTVarWithInvariant :: forall (m :: Type -> Type) a. (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> STM m (StrictTVar m a) Source #

readTVar :: forall (m :: Type -> Type) a. MonadSTM m => StrictTVar m a -> STM m a Source #

stateTVar :: forall (m :: Type -> Type) s a. MonadSTM m => StrictTVar m s -> (s -> (a, s)) -> STM m a Source #

swapTVar :: forall (m :: Type -> Type) a. MonadSTM m => StrictTVar m a -> a -> STM m a Source #

toLazyTVar :: forall (m :: Type -> Type) a. StrictTVar m a -> LazyTVar m a Source #

Get the underlying TVar

Since we obviously cannot guarantee that updates to this LazyTVar will be strict, this should be used with caution.

Similarly, we can not guarantee that updates to this LazyTVar do not break the original invariant that the StrictTVar held.

unsafeToUncheckedStrictTVar :: forall (m :: Type -> Type) a. StrictTVar m a -> StrictTVar m a Source #

Create an unchecked reference to the given checked StrictTVar.

Note that the invariant is only guaranteed when modifying the checked TVar. Any modification to the unchecked reference might break the invariants.

writeTVar :: forall (m :: Type -> Type) a. (MonadSTM m, HasCallStack) => StrictTVar m a -> a -> STM m () Source #

MonadLabelSTM

labelTVar :: forall (m :: Type -> Type) a. MonadLabelledSTM m => StrictTVar m a -> String -> STM m () Source #

MonadTraceSTM

traceTVar :: forall (m :: Type -> Type) proxy a. MonadTraceSTM m => proxy m -> StrictTVar m a -> (Maybe a -> a -> InspectMonadSTM m TraceValue) -> STM m () Source #

Invariant

checkInvariant :: HasCallStack => Maybe String -> a -> a Source #

Check invariant (if enabled) before continuing

checkInvariant mErr x is equal to x if mErr == Nothing, and throws an error err if mErr == Just err.

This is exported so that other code that wants to conditionally check invariants can reuse the same logic, rather than having to introduce new per-package flags.