HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulestm-chans-3.0.0.11Haskell2010

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.

Contents
  1. The TMChan type
  2. Creating TMChans
  3. Reading from TMChans
  4. Writing to TMChans
  5. Closing TMChans
  6. Predicates
Synopsis

The TMChan type

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.

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