HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulestm-chans-3.0.0.9Haskell2010

Control.Concurrent.STM.TMChan

A version of Control.Concurrent.STM.TChan where the queue is closeable. This is similar to a TChan (Maybe a) with a monotonicity guarantee that once there's a Nothing there will always be Nothing.

  • 1 type
  • 14 values
  • Packagestm-chans-3.0.0.9
  • Exports15
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTMChan.hs

The TMChan type

1 declaration
datadata TMChan a
#

TMChan is an abstract type representing a closeable FIFO channel.

Creating TMChans

valuedupTMChan :: TMChan a -> STM (TMChan a)
#

Duplicate a TMChan: the duplicate channel begins empty, but data written to either channel from then on will be available from both, and closing one copy will close them all. Hence this creates a kind of broadcast channel, where data written by anyone is seen by everyone else.

Reading from TMChans

valuereadTMChan :: TMChan a -> STM (Maybe a)
#

Read the next value from the TMChan, retrying if the channel is empty (and not closed). We return Nothing immediately if the channel is closed and empty.

valuetryReadTMChan :: TMChan a -> STM (Maybe (Maybe a))
#

A version of readTMChan which does not retry. Instead it returns Just Nothing if the channel is open but no value is available; it still returns Nothing if the channel is closed and empty.

valuepeekTMChan :: TMChan a -> STM (Maybe a)
#

Get the next value from the TMChan without removing it, retrying if the channel is empty.

valuetryPeekTMChan :: TMChan a -> STM (Maybe (Maybe a))
#

A version of peekTMChan which does not retry. Instead it returns Just Nothing if the channel is open but no value is available; it still returns Nothing if the channel is closed and empty.

Writing to TMChans

valuewriteTMChan :: TMChan a -> a -> STM ()
#

Write a value to a TMChan. If the channel is closed then the value is silently discarded. Use isClosedTMChan to determine if the channel is closed before writing, as needed.

valueunGetTMChan :: TMChan a -> a -> STM ()
#

Put a data item back onto a channel, where it will be the next item read. If the channel is closed then the value is silently discarded; you can use peekTMChan to circumvent this in certain circumstances.

Closing TMChans

Predicates