| Copyright | (c) 2016 Michael Walker |
|---|---|
| License | MIT |
| Maintainer | Michael Walker <mike@barrucadu.co.uk> |
| Stability | stable |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Concurrent.Classy.STM.TBQueue
Contents
Description
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.
Synopsis
- data TBQueue stm a
- newTBQueue :: MonadSTM stm => Natural -> stm (TBQueue stm a)
- readTBQueue :: MonadSTM stm => TBQueue stm a -> stm a
- tryReadTBQueue :: MonadSTM stm => TBQueue stm a -> stm (Maybe a)
- flushTBQueue :: MonadSTM stm => TBQueue stm a -> stm [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 ()
- lengthTBQueue :: MonadSTM stm => TBQueue stm a -> stm Natural
- 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.9.0.0
Arguments
| :: MonadSTM stm | |
| => Natural | maximum number of elements the queue can hold |
| -> stm (TBQueue stm a) |
Builds and returns a new instance of TBQueue
Since: 1.9.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
flushTBQueue :: MonadSTM stm => TBQueue stm a -> stm [a] Source #
Efficiently read the entire contents of a TBQueue into a list. This
function never retries.
Since: 1.6.1.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
lengthTBQueue :: MonadSTM stm => TBQueue stm a -> stm Natural Source #
Return the length of a TBQueue.
Since: 1.9.0.0