concurrency-1.11.0.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.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.

Since: 1.0.0.0

Construction

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

Build and return a new instance of TChan

Since: 1.0.0.0

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.

Since: 1.0.0.0

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.

Since: 1.0.0.0

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.

Since: 1.0.0.0

Reading and writing

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

Read the next value from the TChan.

Since: 1.0.0.0

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.

Since: 1.0.0.0

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.

Since: 1.0.0.0

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.

Since: 1.0.0.0

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

Write a value to a TChan.

Since: 1.0.0.0

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.

Since: 1.0.0.0

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

Returns True if the supplied TChan is empty.

Since: 1.0.0.0