ouroboros-network
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Class.MonadSTM.Strict.TMergeVar

Description

STM TMergeVar mini-abstraction

Synopsis

Documentation

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

The TMergeVar is like a TMVar in that we take it, leaving it empty. Unlike an ordinary TMVar with a blocking 'put' operation, it has a non-blocking combining write operation: if a value is already present then the values are combined using the Semigroup operator.

This is used much like a TMVar as a one-place queue between threads but with the property that we can "improve" the current value (if any).

newTMergeVar :: forall (m :: Type -> Type) a. MonadSTM m => STM m (TMergeVar m a) Source #

writeTMergeVar :: forall (m :: Type -> Type) a. (MonadSTM m, Semigroup a) => TMergeVar m a -> a -> STM m a Source #

Merge the current value with the given one and store it, return the updated value.

takeTMergeVar :: forall (m :: Type -> Type) a. MonadSTM m => TMergeVar m a -> STM m a Source #

tryReadTMergeVar :: forall (m :: Type -> Type) a. MonadSTM m => TMergeVar m a -> STM m (Maybe a) Source #