dejafu-0.3.0.0: Overloadable primitives for testable, potentially non-deterministic, concurrency.

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Classy.STM.TChan

Contents

Description

Transactional channels

Deviations: TChan as defined here does not have an Eq instance, this is because the MonadSTM TVar type does not have an Eq constraint. Furthermore, the newTChanIO and newBroadcastTChanIO functions are not provided.

Synopsis

TChans

data TChan stm a Source

TChan is an abstract type representing an unbounded FIFO channel.

Construction

newTChan :: MonadSTM stm => stm (TChan stm a) Source

Build and return a new instance of TChan

newBroadcastTChan :: MonadSTM stm => stm (TChan stm a) Source

Create a write-only TChan. More precisely, readTChan will retry even after items have been written to the channel. The only way to read a broadcast channel is to duplicate it with dupTChan.

dupTChan :: MonadSTM stm => TChan stm a -> stm (TChan stm a) Source

Duplicate a TChan: the duplicate channel begins empty, but data written to either channel from then on will be available from both. Hence this creates a kind of broadcast channel, where data written by anyone is seen by everyone else.

cloneTChan :: MonadSTM stm => TChan stm a -> stm (TChan stm a) Source

Clone a TChan: similar to dupTChan, but the cloned channel starts with the same content available as the original channel.

Reading and writing

readTChan :: MonadSTM stm => TChan stm a -> stm a Source

Read the next value from the TChan.

tryReadTChan :: MonadSTM stm => TChan stm a -> stm (Maybe a) Source

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

peekTChan :: MonadSTM stm => TChan stm a -> stm a Source

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

tryPeekTChan :: MonadSTM stm => TChan stm a -> stm (Maybe a) Source

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

writeTChan :: MonadSTM stm => TChan stm a -> a -> stm () Source

Write a value to a TChan.

unGetTChan :: MonadSTM stm => TChan stm a -> a -> stm () Source

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

isEmptyTChan :: MonadSTM stm => TChan stm a -> stm Bool Source

Returns True if the supplied TChan is empty.