hoare
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Concurrent.Channel

Description

Tools for connecting communicating sequential processes (threads) with closeable channels.

Synopsis

Documentation

class Channel (c :: Type -> Type) where Source #

Any closeable STM-based pipe for inter-thread communication.

Methods

readChannel :: c a -> STM (Maybe a) Source #

Returns Just value until the channel is closed, blocking for the next value.

writeChannel :: c a -> a -> STM Bool Source #

Writes the given value to the channel if it's still open.

Returns whether the channel is still open so producers know when consumers no longer care.

closeChannel :: c a -> STM () Source #

Closes the channel so that future writes are no-ops and readers get Nothing once all previously-written values are read.

isClosedChannel :: c a -> STM Bool Source #

Instances

Instances details
Channel TBCQueue Source # 
Instance details

Defined in Control.Concurrent.Channel

writeChannel' :: Channel c => c a -> a -> STM () Source #

Writes to the channel, asserting that it hasn't been closed.

Useful in situations where only the writer closes the channel.

evalWriteChannel :: (Channel c, NFData a) => c a -> a -> IO Bool Source #

Force a value to normal form before writing it to the given channel.

One of the goals of CSP is to divide work into independent tasks. Forcing values before passing them to the next actor can improve performance—it keeps the last one in the chain from doing more than its share of evaluation.

consumeChannel :: (Channel c, Monoid m) => c a -> (a -> IO m) -> IO m Source #

Consume the given channel until it closes, passing values to the given action and collecting its results.

stateConsumeChannel :: Channel c => c a -> s -> (s -> a -> IO s) -> IO s Source #

Consume the given channel until it closes, with each action updating some state. Returns the final state.

feedChannel :: Channel c => c a -> IO (Maybe a) -> IO () Source #

Produce values with the given IO action, feeding them into the given channel until it closes or the action returns Nothing.

evalFeedChannel :: (Channel c, NFData a) => c a -> IO (Maybe a) -> IO () Source #

feedChannel, but forces produced values.

See evalWriteChannel for the motivation.

pipeline :: Channel c => IO (c a) -> (c a -> IO x) -> (c a -> IO y) -> IO (x, y) Source #

Create a channel with the given action, then wire it to the given producer and consumer.

pipeline_ :: Channel c => IO (c a) -> (c a -> IO x) -> (c a -> IO y) -> IO () Source #

pipeline, but ignore the results.