Copyright | (c) 2016 Michael Walker |
---|---|
License | MIT |
Maintainer | Michael Walker <mike@barrucadu.co.uk> |
Stability | stable |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
TBQueue
is a bounded version of TQueue
. The queue has a maximum
capacity set when it is created. If the queue already contains the
maximum number of elements, then writeTBQueue
blocks until an
element is removed from the queue.
The implementation is based on the traditional purely-functional queue representation that uses two lists to obtain amortised O(1) enqueue and dequeue operations.
Deviations: TBQueue
as defined here does not have an Eq
instance, this is because the MonadSTM
TVar
type does not have
an Eq
constraint. Furthermore, the newTBQueueIO
function is not
provided.
- data TBQueue stm a
- newTBQueue :: MonadSTM stm => Int -> stm (TBQueue stm a)
- readTBQueue :: MonadSTM stm => TBQueue stm a -> stm a
- tryReadTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a)
- peekTBQueue :: MonadSTM stm => TBQueue stm a -> stm a
- tryPeekTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a)
- writeTBQueue :: MonadSTM stm => TBQueue stm a -> a -> stm ()
- unGetTBQueue :: MonadSTM stm => TBQueue stm a -> a -> stm ()
- isEmptyTBQueue :: MonadSTM stm => TBQueue stm a -> stm Bool
- isFullTBQueue :: MonadSTM stm => TBQueue stm a -> stm Bool
TBQueue
TBQueue
is an abstract type representing a bounded FIFO
channel.
Since: 1.0.0.0
Build and returns a new instance of TBQueue
Since: 1.0.0.0
readTBQueue :: MonadSTM stm => TBQueue stm a -> stm a Source #
Read the next value from the TBQueue
.
Since: 1.0.0.0
tryReadTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a) Source #
A version of readTBQueue
which does not retry. Instead it
returns Nothing
if no value is available.
Since: 1.0.0.0
peekTBQueue :: MonadSTM stm => TBQueue stm a -> stm a Source #
Get the next value from the TBQueue
without removing it,
retrying if the channel is empty.
Since: 1.0.0.0
tryPeekTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a) Source #
A version of peekTBQueue
which does not retry. Instead it
returns Nothing
if no value is available.
Since: 1.0.0.0
writeTBQueue :: MonadSTM stm => TBQueue stm a -> a -> stm () Source #
Write a value to a TBQueue
; retries if the queue is full.
Since: 1.0.0.0
unGetTBQueue :: MonadSTM stm => TBQueue stm a -> a -> stm () Source #
Put a data item back onto a channel, where it will be the next item read. Retries if the queue is full.
Since: 1.0.0.0