concurrency-1.6.1.0: Typeclasses, functions, and data types for concurrency and STM.

Copyright(c) 2016 Michael Walker
LicenseMIT
MaintainerMichael Walker <mike@barrucadu.co.uk>
Stabilitystable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

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

TBQueue

data TBQueue stm a Source #

TBQueue is an abstract type representing a bounded FIFO channel.

Since: concurrency-1.0.0.0

newTBQueue Source #

Arguments

:: MonadSTM stm 
=> Int

maximum number of elements the queue can hold

-> stm (TBQueue stm a) 

Build and returns a new instance of TBQueue

Since: concurrency-1.0.0.0

readTBQueue :: MonadSTM stm => TBQueue stm a -> stm a Source #

Read the next value from the TBQueue.

Since: concurrency-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: concurrency-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: concurrency-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: concurrency-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: concurrency-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: concurrency-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: concurrency-1.0.0.0

lengthTBQueue :: MonadSTM stm => TBQueue stm a -> stm Int Source #

Return the length of a TBQueue.

Since: concurrency-1.6.1.0

isEmptyTBQueue :: MonadSTM stm => TBQueue stm a -> stm Bool Source #

Returns True if the supplied TBQueue is empty.

Since: concurrency-1.0.0.0

isFullTBQueue :: MonadSTM stm => TBQueue stm a -> stm Bool Source #

Returns True if the supplied TBQueue is full.

Since: concurrency-1.0.0.0