Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- castStrictSVar ∷ (TMVar m ~ TMVar n, TVar m ~ TVar n) ⇒ StrictSVar m a → StrictSVar n a
- isEmptySVar ∷ MonadSTM m ⇒ StrictSVar m a → m Bool
- modifySVar ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m (a, b)) → m b
- modifySVar_ ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m a) → m ()
- newEmptySVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a)
- newEmptySVarWithInvariant ∷ MonadSTM m ⇒ (a → Maybe String) → a → m (StrictSVar m a)
- newSVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a)
- newSVarWithInvariant ∷ (MonadSTM m, HasCallStack) ⇒ (a → Maybe String) → a → m (StrictSVar m a)
- putSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m ()
- readSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a
- readSVarSTM ∷ MonadSTM m ⇒ StrictSVar m a → STM m a
- swapSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m a
- takeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a
- tryPutSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m Bool
- tryReadSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a)
- tryTakeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a)
- updateSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → (a, b)) → m b
- updateSVar_ ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → a) → m ()
- data StrictSVar m a = StrictSVar {}
Documentation
castStrictSVar ∷ (TMVar m ~ TMVar n, TVar m ~ TVar n) ⇒ StrictSVar m a → StrictSVar n a Source #
isEmptySVar ∷ MonadSTM m ⇒ StrictSVar m a → m Bool Source #
modifySVar ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m (a, b)) → m b Source #
modifySVar_ ∷ (MonadSTM m, MonadCatch m, HasCallStack) ⇒ StrictSVar m a → (a → m a) → m () Source #
newEmptySVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a) Source #
newEmptySVarWithInvariant Source #
∷ MonadSTM m | |
⇒ (a → Maybe String) | Invariant (expect |
→ a | The initial stale value |
→ m (StrictSVar m a) |
Create an initially empty StrictSVar
NOTE: Since readSVarSTM
allows to read the StrictSVar
even when it is
empty, we need an initial value of a
even though the StrictSVar
starts
out empty. However, we are NOT strict in this value, to allow it to be
error
.
newSVar ∷ MonadSTM m ⇒ a → m (StrictSVar m a) Source #
∷ (MonadSTM m, HasCallStack) | |
⇒ (a → Maybe String) | Invariant (expect |
→ a | |
→ m (StrictSVar m a) |
putSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m () Source #
readSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a Source #
readSVarSTM ∷ MonadSTM m ⇒ StrictSVar m a → STM m a Source #
Read the possibly-stale value of the SVar
Will return the current value of the SVar
if it non-empty, or the last
known value otherwise.
swapSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m a Source #
Swap value of a StrictSVar
NOTE: Since swapping the value can't leave the StrictSVar
empty, we
could check the invariant first and only then swap. We nonetheless swap
first and check the invariant after to keep the semantics the same with
putSVar
, otherwise it will be difficult to understand when a StrictSVar
is updated and when it is not.
takeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m a Source #
tryPutSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → a → m Bool Source #
tryReadSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a) Source #
tryTakeSVar ∷ MonadSTM m ⇒ StrictSVar m a → m (Maybe a) Source #
updateSVar ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → (a, b)) → m b Source #
updateSVar_ ∷ (MonadSTM m, HasCallStack) ⇒ StrictSVar m a → (a → a) → m () Source #
constructors exported for benefit of tests
data StrictSVar m a Source #
Strict SVar (modelled using a lazy TMVar
under the hood)
The StrictSVar
API is slightly stronger than the usual SVar
one, as we
offer a primitive to read the value of the SVar even if it is empty (in which
case we will return the oldest known stale one). See readSVarSTM
.
There is a weaker invariant for a StrictSVar
than for a StrictTVar
:
although all functions that modify the StrictSVar
check the invariant, we
do not guarantee that the value inside the StrictSVar
always satisfies
the invariant. Instead, we do guarantee that if the StrictSVar
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 SVar
empty can lead to
very hard to debug "blocked indefinitely" problems.
This is also the reason we do not offer support for an invariant in
StrictTMVar
: if we throw an exception from an STM transaction, the STM
transaction is not executed, and so we would not even be able to provide the
weaker guarantee that we provide for StrictSVar
.
StrictSVar | |
|
Instances
NoThunks a ⇒ NoThunks (StrictSVar IO a) Source # | |
NoThunks (StrictSVar m a) ⇒ NoThunks (StrictSVar (WithEarlyExit m) a) Source # | |
Defined in Ouroboros.Consensus.Util.EarlyExit noThunks ∷ Context → StrictSVar (WithEarlyExit m) a → IO (Maybe ThunkInfo) Source # wNoThunks ∷ Context → StrictSVar (WithEarlyExit m) a → IO (Maybe ThunkInfo) Source # showTypeOf ∷ Proxy (StrictSVar (WithEarlyExit m) a) → String Source # |