chp-1.5.0: An implementation of concurrency ideas from Communicating Sequential ProcessesSource codeContentsIndex
Control.Concurrent.CHP.Channels.BroadcastReduce
Description

A module containing broadcast channels (one-to-many). Whereas a one-to-any channel features one writer sending a single value to one (of many) readers, a one-to-many channel features one writer sending the same value to many readers. So a one-to-any channel involves claiming the channel-end to ensure exclusivity, but a one-to-many channel involves enrolling on the channel-end (subscribing) before it can engage in communication.

A communication on a one-to-many channel only takes place when the writer and all readers currently enrolled agree to communicate. What happens when the writer wants to communicate and no readers are enrolled is undefined (the writer may block, or may communicate happily to no-one).

This module also contains reduce channels (added in version 1.1.1). Because in CHP channels must have the same type at both ends, we use the Monoid type-class. It is important to be aware that the order of mappends will be non-deterministic, and thus you should either use an mappend that is commutative or code around this restruction.

For example, a common thing to do would be to use lists as the type for reduce channels, make each writer write a single item list (but more is possible), then use the list afterwards, but be aware that it is unordered. If it is important to have an ordered list, make each writer write a pair containing a (unique) index value and the real data, then sort by the index value and discard it.

Since reduce channels were added after the initial library design, there is a slight complication: it is not possible to use newChannel (and all similar functions) with reduce channels because it is impossible to express the Monoid constraint for the Channel instance. Instead, you must use manyToOneChannel and manyToAnyChannel.

Synopsis
data BroadcastChanin a
data BroadcastChanout a
type OneToManyChannel = Chan BroadcastChanin BroadcastChanout
type AnyToManyChannel = Chan BroadcastChanin (Shared BroadcastChanout)
oneToManyChannel :: MonadCHP m => m (OneToManyChannel a)
anyToManyChannel :: MonadCHP m => m (AnyToManyChannel a)
oneToManyChannel' :: MonadCHP m => ChanOpts a -> m (OneToManyChannel a)
anyToManyChannel' :: MonadCHP m => ChanOpts a -> m (AnyToManyChannel a)
data ReduceChanin a
data ReduceChanout a
sameReduceChannel :: ReduceChanin a -> ReduceChanout a -> Bool
type ManyToOneChannel = Chan ReduceChanin ReduceChanout
type ManyToAnyChannel = Chan (Shared ReduceChanin) ReduceChanout
manyToOneChannel :: (Monoid a, MonadCHP m) => m (ManyToOneChannel a)
manyToAnyChannel :: (Monoid a, MonadCHP m) => m (ManyToAnyChannel a)
manyToOneChannel' :: (Monoid a, MonadCHP m) => ChanOpts a -> m (ManyToOneChannel a)
manyToAnyChannel' :: (Monoid a, MonadCHP m) => ChanOpts a -> m (ManyToAnyChannel a)
Documentation
data BroadcastChanin a Source

The reading end of a broadcast channel. You must enroll on it before you can read from it or poison it.

The Eq instance was added in version 1.4.0.

show/hide Instances
data BroadcastChanout a Source

The writing end of a broadcast channel.

The Eq instance was added in version 1.4.0.

show/hide Instances
type OneToManyChannel = Chan BroadcastChanin BroadcastChanoutSource
type AnyToManyChannel = Chan BroadcastChanin (Shared BroadcastChanout)Source
oneToManyChannel :: MonadCHP m => m (OneToManyChannel a)Source
anyToManyChannel :: MonadCHP m => m (AnyToManyChannel a)Source
oneToManyChannel' :: MonadCHP m => ChanOpts a -> m (OneToManyChannel a)Source

Added in version 1.5.0.

In version 1.5.0, the broadcast and reduce channels do not appear correctly in the traces.

anyToManyChannel' :: MonadCHP m => ChanOpts a -> m (AnyToManyChannel a)Source

Added in version 1.5.0.

In version 1.5.0, the broadcast and reduce channels do not appear correctly in the traces.

data ReduceChanin a Source

The reading end of a reduce channel.

The Eq instance was added in version 1.4.0.

show/hide Instances
data ReduceChanout a Source

The writing end of a reduce channel. You must enroll on it before you can read from it or poison it.

The Eq instance was added in version 1.4.0.

show/hide Instances
sameReduceChannel :: ReduceChanin a -> ReduceChanout a -> BoolSource

The reduce channel version of sameChannel.

This function was added in version 1.4.0.

type ManyToOneChannel = Chan ReduceChanin ReduceChanoutSource
type ManyToAnyChannel = Chan (Shared ReduceChanin) ReduceChanoutSource
manyToOneChannel :: (Monoid a, MonadCHP m) => m (ManyToOneChannel a)Source
manyToAnyChannel :: (Monoid a, MonadCHP m) => m (ManyToAnyChannel a)Source
manyToOneChannel' :: (Monoid a, MonadCHP m) => ChanOpts a -> m (ManyToOneChannel a)Source

Added in version 1.5.0.

In version 1.5.0, the broadcast and reduce channels do not appear correctly in the traces.

manyToAnyChannel' :: (Monoid a, MonadCHP m) => ChanOpts a -> m (ManyToAnyChannel a)Source

Added in version 1.5.0.

In version 1.5.0, the broadcast and reduce channels do not appear correctly in the traces.

Produced by Haddock version 2.4.2