stm-2.4.2: Software Transactional Memory

Portability | non-portable (requires STM)
Stability | experimental
Maintainer | libraries@haskell.org
Safe Haskell | Trustworthy

Control.Concurrent.STM.TQueue

Contents

- TQueue

Description

A `TQueue` is like a `TChan`, with two important differences:

- it has faster throughput than both `TChan` and `Chan` (although the costs are amortised, so the cost of individual operations can vary a lot).
- it does not provide equivalents of the `dupTChan` and `cloneTChan` 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.

Synopsis

- data TQueue a
- newTQueue :: STM (TQueue a)
- newTQueueIO :: IO (TQueue a)
- readTQueue :: TQueue a -> STM a
- tryReadTQueue :: TQueue a -> STM (Maybe a)
- peekTQueue :: TQueue a -> STM a
- tryPeekTQueue :: TQueue a -> STM (Maybe a)
- writeTQueue :: TQueue a -> a -> STM ()
- unGetTQueue :: TQueue a -> a -> STM ()
- isEmptyTQueue :: TQueue a -> STM Bool

# TQueue

data TQueue a Source

`TQueue` is an abstract type representing an unbounded FIFO channel.

Instances

Typeable1 TQueue |
Eq (TQueue a) |

newTQueue :: STM (TQueue a)Source

Build and returns a new instance of `TQueue`

newTQueueIO :: IO (TQueue a)Source

`IO` version of `newTQueue`. This is useful for creating top-level `TQueue`s using `unsafePerformIO`, because using `atomically` inside `unsafePerformIO` isn't possible.

readTQueue :: TQueue a -> STM aSource

Read the next value from the `TQueue`.

tryReadTQueue :: TQueue a -> STM (Maybe a)Source

A version of `readTQueue` which does not retry. Instead it returns `Nothing` if no value is available.

peekTQueue :: TQueue a -> STM aSource

Get the next value from the `TQueue` without removing it, retrying if the channel is empty.

tryPeekTQueue :: TQueue a -> STM (Maybe a)Source

A version of `peekTQueue` which does not retry. Instead it returns `Nothing` if no value is available.

writeTQueue :: TQueue a -> a -> STM ()Source

Write a value to a `TQueue`.

unGetTQueue :: TQueue a -> a -> STM ()Source

Put a data item back onto a channel, where it will be the next item read.

isEmptyTQueue :: TQueue a -> STM Bool Source

Returns `True` if the supplied `TQueue` is empty.