Safe Haskell | None |
---|---|
Language | Haskell2010 |
Control.Concurrent.Class.MonadMVar.Strict.Checked
Contents
Description
This module corresponds to Control.Concurrent.MVar in the base
package.
This module can be used as a drop-in replacement for Control.Concurrent.Class.MonadMVar.Strict, but not the other way around.
Synopsis
- type LazyMVar (m :: Type -> Type) = MVar m
- data StrictMVar (m :: Type -> Type) a
- castStrictMVar :: forall (m :: Type -> Type) (n :: Type -> Type) a. LazyMVar m ~ LazyMVar n => StrictMVar m a -> StrictMVar n a
- fromLazyMVar :: forall (m :: Type -> Type) a. LazyMVar m a -> StrictMVar m a
- isEmptyMVar :: MonadMVar m => StrictMVar m a -> m Bool
- modifyMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m (a, b)) -> m b
- modifyMVarMasked :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m (a, b)) -> m b
- modifyMVarMasked_ :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m a) -> m ()
- modifyMVar_ :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m a) -> m ()
- newEmptyMVar :: MonadMVar m => m (StrictMVar m a)
- newEmptyMVarWithInvariant :: MonadMVar m => (a -> Maybe String) -> m (StrictMVar m a)
- newMVar :: MonadMVar m => a -> m (StrictMVar m a)
- newMVarWithInvariant :: (HasCallStack, MonadMVar m) => (a -> Maybe String) -> a -> m (StrictMVar m a)
- putMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m ()
- readMVar :: MonadMVar m => StrictMVar m a -> m a
- swapMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m a
- takeMVar :: MonadMVar m => StrictMVar m a -> m a
- toLazyMVar :: forall (m :: Type -> Type) a. StrictMVar m a -> LazyMVar m a
- tryPutMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m Bool
- tryReadMVar :: MonadMVar m => StrictMVar m a -> m (Maybe a)
- tryTakeMVar :: MonadMVar m => StrictMVar m a -> m (Maybe a)
- unsafeToUncheckedStrictMVar :: forall (m :: Type -> Type) a. StrictMVar m a -> StrictMVar m a
- withMVar :: MonadMVar m => StrictMVar m a -> (a -> m b) -> m b
- withMVarMasked :: MonadMVar m => StrictMVar m a -> (a -> m b) -> m b
- checkInvariant :: HasCallStack => Maybe String -> a -> a
- class Monad m => MonadMVar (m :: Type -> Type)
StrictMVar
data StrictMVar (m :: Type -> Type) a Source #
A strict MVar with invariant checking.
There is a weaker invariant for a StrictMVar
than for a StrictTVar
:
although all functions that modify the StrictMVar
check the invariant, we
do not guarantee that the value inside the StrictMVar
always satisfies
the invariant. Instead, we do guarantee that if the StrictMVar
is updated
with a value that does not satisfy the invariant, an exception is thrown. The
reason for this weaker guarantee is that leaving an MVar
empty can lead to
very hard to debug "blocked indefinitely" problems.
castStrictMVar :: forall (m :: Type -> Type) (n :: Type -> Type) a. LazyMVar m ~ LazyMVar n => StrictMVar m a -> StrictMVar n a Source #
fromLazyMVar :: forall (m :: Type -> Type) a. LazyMVar m a -> StrictMVar m a Source #
Create a StrictMVar
from a LazyMVar
It is not guaranteed that the LazyMVar
contains a value that is in WHNF, so
there is no guarantee that the resulting StrictMVar
contains a value that
is in WHNF. This should be used with caution.
The resulting StrictMVar
has a trivial invariant.
isEmptyMVar :: MonadMVar m => StrictMVar m a -> m Bool Source #
modifyMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m (a, b)) -> m b Source #
modifyMVarMasked :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m (a, b)) -> m b Source #
modifyMVarMasked_ :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m a) -> m () Source #
modifyMVarMasked_
is defined in terms of modifyMVarMasked
.
modifyMVar_ :: (HasCallStack, MonadMVar m) => StrictMVar m a -> (a -> m a) -> m () Source #
modifyMVar_
is defined in terms of modifyMVar
.
newEmptyMVar :: MonadMVar m => m (StrictMVar m a) Source #
newEmptyMVarWithInvariant :: MonadMVar m => (a -> Maybe String) -> m (StrictMVar m a) Source #
newMVar :: MonadMVar m => a -> m (StrictMVar m a) Source #
newMVarWithInvariant :: (HasCallStack, MonadMVar m) => (a -> Maybe String) -> a -> m (StrictMVar m a) Source #
Create a StrictMVar
with an invariant.
Contrary to functions that modify a StrictMVar
, this function checks the
invariant before putting the value in a new StrictMVar
.
putMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m () Source #
readMVar :: MonadMVar m => StrictMVar m a -> m a Source #
swapMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m a Source #
takeMVar :: MonadMVar m => StrictMVar m a -> m a Source #
toLazyMVar :: forall (m :: Type -> Type) a. StrictMVar m a -> LazyMVar m a Source #
Get the underlying MVar
Since we obviously can not guarantee that updates to this LazyMVar
will be
strict, this should be used with caution.
Similarly, we can not guarantee that updates to this LazyMVar
do not break
the original invariant that the StrictMVar
held.
tryPutMVar :: (HasCallStack, MonadMVar m) => StrictMVar m a -> a -> m Bool Source #
tryReadMVar :: MonadMVar m => StrictMVar m a -> m (Maybe a) Source #
tryTakeMVar :: MonadMVar m => StrictMVar m a -> m (Maybe a) Source #
unsafeToUncheckedStrictMVar :: forall (m :: Type -> Type) a. StrictMVar m a -> StrictMVar m a Source #
Create an unchecked reference to the given checked StrictMVar
.
Note that the invariant is only guaranteed when modifying the checked MVar. Any modification to the unchecked reference might break the invariants.
withMVar :: MonadMVar m => StrictMVar m a -> (a -> m b) -> m b Source #
withMVarMasked :: MonadMVar m => StrictMVar m a -> (a -> m b) -> m b 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.
Re-exports
class Monad m => MonadMVar (m :: Type -> Type) #
Minimal complete definition
newEmptyMVar, takeMVar, tryTakeMVar, putMVar, tryPutMVar, readMVar, tryReadMVar, isEmptyMVar