HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelvar-0.1.0.0Haskell2010

Data.LVar

LVar is like Control.Concurrent.STM.TMVar but with a capability for listening to its changes.

  • 2 types
  • 8 values
  • Packagelvar-0.1.0.0
  • Exports10
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceLVar.hs

Types

2 declarations

Creating a LVar

2 declarations
valuenew :: MonadIO m => a -> m (LVar a)
#

Create a new LVar with the given initial value

valueempty :: MonadIO m => m (LVar a)
#

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

3 declarations
valueset :: MonadIO m => LVar a -> a -> m ()
#

Set the LVar value; active listeners are automatically notifed.

valuemodify :: MonadIO m => LVar a -> (a -> a) -> m ()
#

Modify the LVar value; active listeners are automatically notified.

Listening to a LVar

3 declarations
valueaddListener :: MonadIO m => LVar a -> m ListenerId
#

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)

valuelistenNext :: MonadIO m => LVar a -> ListenerId -> m a
#

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.