| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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
- type LazyTVar (m :: Type -> Type) = LazyTVar m
- data StrictTVar (m :: Type -> Type) a
- castStrictTVar :: forall (m :: Type -> Type) (n :: Type -> Type) a. LazyTVar m ~ LazyTVar n => StrictTVar m a -> StrictTVar n a
- fromLazyTVar :: forall (m :: Type -> Type) a. LazyTVar m a -> StrictTVar m a
- modifyTVar :: forall (m :: Type -> Type) a. MonadSTM m => StrictTVar m a -> (a -> a) -> STM m ()
- newTVar :: forall (m :: Type -> Type) a. MonadSTM m => a -> STM m (StrictTVar m a)
- newTVarIO :: MonadSTM m => a -> m (StrictTVar m a)
- newTVarWithInvariant :: forall (m :: Type -> Type) a. (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> STM m (StrictTVar m a)
- newTVarWithInvariantIO :: (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> m (StrictTVar m a)
- readTVar :: forall (m :: Type -> Type) a. MonadSTM m => StrictTVar m a -> STM m a
- readTVarIO :: MonadSTM m => StrictTVar m a -> m a
- stateTVar :: forall (m :: Type -> Type) s a. MonadSTM m => StrictTVar m s -> (s -> (a, s)) -> STM m a
- swapTVar :: forall (m :: Type -> Type) a. MonadSTM m => StrictTVar m a -> a -> STM m a
- toLazyTVar :: forall (m :: Type -> Type) a. StrictTVar m a -> LazyTVar m a
- unsafeToUncheckedStrictTVar :: forall (m :: Type -> Type) a. StrictTVar m a -> StrictTVar m a
- writeTVar :: forall (m :: Type -> Type) a. (MonadSTM m, HasCallStack) => StrictTVar m a -> a -> STM m ()
- labelTVar :: forall (m :: Type -> Type) a. MonadLabelledSTM m => StrictTVar m a -> String -> STM m ()
- labelTVarIO :: MonadLabelledSTM m => StrictTVar m a -> String -> m ()
- traceTVar :: forall (m :: Type -> Type) proxy a. MonadTraceSTM m => proxy m -> StrictTVar m a -> (Maybe a -> a -> InspectMonadSTM m TraceValue) -> STM m ()
- traceTVarIO :: MonadTraceSTM m => StrictTVar m a -> (Maybe a -> a -> InspectMonadSTM m TraceValue) -> m ()
- checkInvariant :: HasCallStack => Maybe String -> a -> a
StrictTVar
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 #
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 #
newTVarWithInvariantIO :: (MonadSTM m, HasCallStack) => (a -> Maybe String) -> a -> m (StrictTVar m a) Source #
readTVarIO :: MonadSTM m => StrictTVar m a -> m a Source #
stateTVar :: forall (m :: Type -> Type) s a. MonadSTM m => StrictTVar m s -> (s -> (a, s)) -> 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 #
labelTVarIO :: MonadLabelledSTM m => StrictTVar m a -> String -> 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 #
traceTVarIO :: MonadTraceSTM m => StrictTVar m a -> (Maybe a -> a -> InspectMonadSTM m TraceValue) -> 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.