Portability | non-portable (GHC STM, CPP) |
---|---|
Stability | provisional |
Maintainer | wren@community.haskell.org |
Safe Haskell | Safe-Infered |
Compatibility layer for older versions of the stm
library.
Namely, we define tryReadTChan
, peekTChan
, and tryPeekTChan
which stm<2.3.0
lacks. These implementations are less efficient
than the package versions due to the TChan
type being abstract.
However, this module uses Cabal-style CPP macros in order to use
the package versions when available.
- data TChan a
- newTChan :: STM (TChan a)
- newTChanIO :: IO (TChan a)
- dupTChan :: TChan a -> STM (TChan a)
- readTChan :: TChan a -> STM a
- tryReadTChan :: TChan a -> STM (Maybe a)
- peekTChan :: TChan a -> STM a
- tryPeekTChan :: TChan a -> STM (Maybe a)
- unGetTChan :: TChan a -> a -> STM ()
- writeTChan :: TChan a -> a -> STM ()
- isEmptyTChan :: TChan a -> STM Bool
The TChan type
Creating TChans
newTChanIO :: IO (TChan a)
IO
version of newTChan
. This is useful for creating top-level
TChan
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't
possible.
dupTChan :: TChan a -> STM (TChan a)
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.
Reading from TChans
tryReadTChan :: TChan a -> STM (Maybe a)
A version of readTChan
which does not retry. Instead it
returns Nothing
if no value is available.
Get the next value from the TChan
without removing it,
retrying if the channel is empty.
tryPeekTChan :: TChan a -> STM (Maybe a)
A version of peekTChan
which does not retry. Instead it
returns Nothing
if no value is available.
Writing to TChans
unGetTChan :: TChan a -> a -> STM ()
Put a data item back onto a channel, where it will be the next item read.
writeTChan :: TChan a -> a -> STM ()
Write a value to a TChan
.