Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- cloneTChan :: TChan a -> STM (TChan a)
- isEmptyTChan :: TChan a -> STM Bool
- unGetTChan :: TChan a -> a -> STM ()
- dupTChan :: TChan a -> STM (TChan a)
- tryPeekTChan :: TChan a -> STM (Maybe a)
- peekTChan :: TChan a -> STM a
- tryReadTChan :: TChan a -> STM (Maybe a)
- readTChan :: TChan a -> STM a
- writeTChan :: TChan a -> a -> STM ()
- newBroadcastTChan :: STM (TChan a)
- newTChan :: STM (TChan a)
- data TChan a
- newTChanIO :: MonadIO m => m (TChan a)
- newBroadcastTChanIO :: MonadIO m => m (TChan a)
- dupTChanIO :: MonadIO m => TChan a -> m (TChan a)
- readTChanIO :: MonadIO m => TChan a -> m a
- tryReadTChanIO :: MonadIO m => TChan a -> m (Maybe a)
- peekTChanIO :: MonadIO m => TChan a -> m a
- tryPeekTChanIO :: MonadIO m => TChan a -> m (Maybe a)
- writeTChanIO :: MonadIO m => TChan a -> a -> m ()
- unGetTChanIO :: MonadIO m => TChan a -> a -> m ()
- isEmptyTChanIO :: MonadIO m => TChan a -> m Bool
- cloneTChanIO :: MonadIO m => TChan a -> m (TChan a)
Documentation
cloneTChan :: TChan a -> STM (TChan a) #
Clone a TChan
: similar to dupTChan, but the cloned channel starts with the
same content available as the original channel.
Since: stm-2.4
unGetTChan :: TChan a -> a -> STM () #
Put a data item back onto a channel, where it will be the next item read.
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.
tryPeekTChan :: TChan a -> STM (Maybe a) #
A version of peekTChan
which does not retry. Instead it
returns Nothing
if no value is available.
Since: stm-2.3
peekTChan :: TChan a -> STM a #
Get the next value from the TChan
without removing it,
retrying if the channel is empty.
Since: stm-2.3
tryReadTChan :: TChan a -> STM (Maybe a) #
A version of readTChan
which does not retry. Instead it
returns Nothing
if no value is available.
Since: stm-2.3
writeTChan :: TChan a -> a -> STM () #
Write a value to a TChan
.
newBroadcastTChan :: STM (TChan a) #
Create a write-only TChan
. More precisely, readTChan
will retry
even after items have been written to the channel. The only way to read
a broadcast channel is to duplicate it with dupTChan
.
Consider a server that broadcasts messages to clients:
serve :: TChan Message -> Client -> IO loop serve broadcastChan client = do myChan <- dupTChan broadcastChan forever $ do message <- readTChan myChan send client message
The problem with using newTChan
to create the broadcast channel is that if
it is only written to and never read, items will pile up in memory. By
using newBroadcastTChan
to create the broadcast channel, items can be
garbage collected after clients have seen them.
Since: stm-2.4
TChan
is an abstract type representing an unbounded FIFO channel.
newTChanIO :: MonadIO m => m (TChan a) Source #
newBroadcastTChanIO :: MonadIO m => m (TChan a) Source #
readTChanIO :: MonadIO m => TChan a -> m a Source #
peekTChanIO :: MonadIO m => TChan a -> m a Source #
writeTChanIO :: MonadIO m => TChan a -> a -> m () Source #
unGetTChanIO :: MonadIO m => TChan a -> a -> m () Source #