Portability | non-portable (requires STM) |
---|---|
Stability | experimental |
Maintainer | libraries@haskell.org |
Safe Haskell | Trustworthy |
TChan: Transactional channels (GHC only)
- data TChan a
- newTChan :: STM (TChan a)
- newTChanIO :: IO (TChan a)
- readTChan :: TChan a -> STM a
- tryReadTChan :: TChan a -> STM (Maybe a)
- peekTChan :: TChan a -> STM a
- tryPeekTChan :: TChan a -> STM (Maybe a)
- writeTChan :: TChan a -> a -> STM ()
- dupTChan :: TChan a -> STM (TChan a)
- unGetTChan :: TChan a -> a -> STM ()
- isEmptyTChan :: TChan a -> STM Bool
TChans
TChan
is an abstract type representing an unbounded FIFO channel.
newTChanIO :: IO (TChan a)Source
IO
version of newTChan
. This is useful for creating top-level
TChan
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
tryReadTChan :: TChan a -> STM (Maybe a)Source
A version of readTChan
which does not retry. Instead it
returns Nothing
if no value is available.
peekTChan :: TChan a -> STM aSource
Get the next value from the TChan
without removing it,
retrying if the channel is empty.
tryPeekTChan :: TChan a -> STM (Maybe a)Source
A version of peekTChan
which does not retry. Instead it
returns Nothing
if no value is available.
dupTChan :: TChan a -> STM (TChan a)Source
Duplicate a TChan
: the duplicate channel begins empty, but data written to
either channel from then on will be available from both. Hence this creates
a kind of broadcast channel, where data written by anyone is seen by
everyone else.
unGetTChan :: TChan a -> a -> STM ()Source
Put a data item back onto a channel, where it will be the next item read.