Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
LVar
is like Control.Concurrent.STM.TMVar
but with a capability for
listening to its changes.
Synopsis
- data LVar a
- type ListenerId = Int
- new :: forall a m. MonadIO m => a -> m (LVar a)
- empty :: MonadIO m => m (LVar a)
- get :: MonadIO m => LVar a -> m a
- set :: MonadIO m => LVar a -> a -> m ()
- modify :: MonadIO m => LVar a -> (a -> a) -> m ()
- addListener :: MonadIO m => LVar a -> m ListenerId
- listenNext :: MonadIO m => LVar a -> ListenerId -> m a
- removeListener :: MonadIO m => LVar a -> ListenerId -> m ()
Types
type ListenerId = Int Source #
Creating a LVar
new :: forall a m. MonadIO m => a -> m (LVar a) Source #
Create a new LVar
with the given initial value
empty :: MonadIO m => m (LVar a) Source #
Like new
, but there is no initial value. A get
will block until an
initial value is set using set
or modify
Modifying a LVar
set :: MonadIO m => LVar a -> a -> m () Source #
Set the LVar
value; active listeners are automatically notifed.
modify :: MonadIO m => LVar a -> (a -> a) -> m () Source #
Modify the LVar
value; active listeners are automatically notified.
Listening to a LVar
addListener :: MonadIO m => LVar a -> m ListenerId Source #
Create a listener for changes to the LVar
, as they are set by set
or
modify
from this time onwards.
You must call listenNext
to get the next updated value (or current value if
there is one).
Returns a ListenerId
that can be used to stop listening later (via
removeListener
)
listenNext :: MonadIO m => LVar a -> ListenerId -> m a Source #
Listen for the next value update (since the last listenNext
or
addListener
). Unless the LVar
was empty when addListener
was invoked,
the first invocation of listenNext
will return the current value even if
there wasn't an update. Therefore, the *first* call to listenNext
will
*always* return immediately, unless the LVar
is empty.
Call this in a loop to listen on a series of updates.
Throws ListenerDead
if called with a ListenerId
that got already removed
by removeListener
.
removeListener :: MonadIO m => LVar a -> ListenerId -> m () Source #
Stop listening to the LVar