Copyright | (c) 2016 Michael Walker |
---|---|
License | MIT |
Maintainer | Michael Walker <mike@barrucadu.co.uk> |
Stability | stable |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
A TQueue
is like a TChan
, with two important differences:
- it has faster throughput than both
TChan
andChan
(although the costs are amortised, so the cost of individual operations can vary a lot). - it does not provide equivalents of the
dupTChan
andcloneTChan
operations.
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: TQueue
as defined here does not have an Eq
instance, this is because the MonadSTM
TVar
type does not have
an Eq
constraint. Furthermore, the newTQueueIO
function is not
provided.
Synopsis
- data TQueue stm a
- newTQueue :: MonadSTM stm => stm (TQueue stm a)
- readTQueue :: MonadSTM stm => TQueue stm a -> stm a
- tryReadTQueue :: MonadSTM stm => TQueue stm a -> stm (Maybe a)
- flushTQueue :: MonadSTM stm => TQueue stm a -> stm [a]
- peekTQueue :: MonadSTM stm => TQueue stm a -> stm a
- tryPeekTQueue :: MonadSTM stm => TQueue stm a -> stm (Maybe a)
- writeTQueue :: MonadSTM stm => TQueue stm a -> a -> stm ()
- unGetTQueue :: MonadSTM stm => TQueue stm a -> a -> stm ()
- isEmptyTQueue :: MonadSTM stm => TQueue stm a -> stm Bool
TQueue
TQueue
is an abstract type representing an unbounded FIFO channel.
Since: concurrency-1.0.0.0
newTQueue :: MonadSTM stm => stm (TQueue stm a) Source #
Build and returns a new instance of TQueue
Since: concurrency-1.0.0.0
readTQueue :: MonadSTM stm => TQueue stm a -> stm a Source #
Read the next value from the TQueue
.
Since: concurrency-1.0.0.0
tryReadTQueue :: MonadSTM stm => TQueue stm a -> stm (Maybe a) Source #
A version of readTQueue
which does not retry. Instead it
returns Nothing
if no value is available.
Since: concurrency-1.0.0.0
flushTQueue :: MonadSTM stm => TQueue stm a -> stm [a] Source #
Efficiently read the entire contents of a TQueue
into a list. This
function never retries.
Since: concurrency-1.6.1.0
peekTQueue :: MonadSTM stm => TQueue stm a -> stm a Source #
Get the next value from the TQueue
without removing it,
retrying if the channel is empty.
Since: concurrency-1.0.0.0
tryPeekTQueue :: MonadSTM stm => TQueue stm a -> stm (Maybe a) Source #
A version of peekTQueue
which does not retry. Instead it
returns Nothing
if no value is available.
Since: concurrency-1.0.0.0
writeTQueue :: MonadSTM stm => TQueue stm a -> a -> stm () Source #
Write a value to a TQueue
.
Since: concurrency-1.0.0.0
unGetTQueue :: MonadSTM stm => TQueue stm a -> a -> stm () Source #
Put a data item back onto a channel, where it will be the next item read.
Since: concurrency-1.0.0.0