Portability | non-portable (GHC STM, DeriveDataTypeable) |
---|---|
Stability | experimental |
Maintainer | wren@community.haskell.org |
A version of Control.Concurrent.STM.TChan where the queue is bounded in length.
- data TBChan a
- newTBChan :: Int -> STM (TBChan a)
- newTBChanIO :: Int -> IO (TBChan a)
- readTBChan :: TBChan a -> STM a
- tryReadTBChan :: TBChan a -> STM (Maybe a)
- peekTBChan :: TBChan a -> STM a
- tryPeekTBChan :: TBChan a -> STM (Maybe a)
- writeTBChan :: TBChan a -> a -> STM ()
- tryWriteTBChan :: TBChan a -> a -> STM Bool
- unGetTBChan :: TBChan a -> a -> STM ()
- isEmptyTBChan :: TBChan a -> STM Bool
- isFullTBChan :: TBChan a -> STM Bool
The TBChan type
TBChan
is an abstract type representing a bounded FIFO
channel.
Creating TBChans
newTBChan :: Int -> STM (TBChan a)Source
Build and returns a new instance of TBChan
with the given
capacity. N.B., we do not verify the capacity is positive, but
if it is non-positive then writeTBChan
will always retry and
isFullTBChan
will always be true.
newTBChanIO :: Int -> IO (TBChan a)Source
IO
version of newTBChan
. This is useful for creating
top-level TBChan
s using unsafePerformIO
, because using
atomically
inside unsafePerformIO
isn't possible.
Reading from TBChans
readTBChan :: TBChan a -> STM aSource
Read the next value from the TBChan
, retrying if the channel
is empty.
tryReadTBChan :: TBChan a -> STM (Maybe a)Source
A version of readTBChan
which does not retry. Instead it
returns Nothing
if no value is available.
peekTBChan :: TBChan a -> STM aSource
Get the next value from the TBChan
without removing it,
retrying if the channel is empty.
tryPeekTBChan :: TBChan a -> STM (Maybe a)Source
A version of peekTBChan
which does not retry. Instead it
returns Nothing
if no value is available.
Writing to TBChans
writeTBChan :: TBChan a -> a -> STM ()Source
Write a value to a TBChan
, retrying if the channel is full.
tryWriteTBChan :: TBChan a -> a -> STM BoolSource
A version of writeTBChan
which does not retry. Returns True
if the value was successfully written, and False
otherwise.
unGetTBChan :: TBChan a -> a -> STM ()Source
Put a data item back onto a channel, where it will be the next item read. N.B., this could allow the channel to temporarily become longer than the specified limit, which is necessary to ensure that the item is indeed the next one read.
Predicates
isEmptyTBChan :: TBChan a -> STM BoolSource
Returns True
if the supplied TBChan
is empty (i.e., has
no elements). N.B., a TBChan
can be both `empty'
and
`full'
at the same time, if the initial limit was non-positive.
isFullTBChan :: TBChan a -> STM BoolSource
Returns True
if the supplied TBChan
is full (i.e., is over
its limit). N.B., a TBChan
can be both `empty'
and `full'
at the same time, if the initial limit was non-positive.