chp-1.6.0: An implementation of concurrency ideas from Communicating Sequential ProcessesSource codeContentsIndex
Control.Concurrent.CHP.Actions
Description

A module containing action wrappers around channel-ends.

In CHP, there are a variety of channel-ends. Enrolled Chanin, Shared Chanout, plain Chanin, and so on. The difference between these ends can be important; enrolled channel-ends can be resigned from, shared channel-ends need to be claimed before use. But sometimes you just want to ignore those differences and read and write from the channel-end regardless of its type. In particular, you want to pass a channel-end to a process without the process worrying about its type.

Actions allow you to do this. A send action is like a monadic function (a -> CHP() for sending an item, but can be poisoned too. A recv action is like something of type CHP a that again can be poisoned.

Synopsis
data SendAction a
data RecvAction a
sendAction :: SendAction a -> a -> CHP ()
recvAction :: RecvAction a -> CHP a
makeSendAction :: (WriteableChannel w, Poisonable (w a)) => w a -> SendAction a
makeRecvAction :: (ReadableChannel r, Poisonable (r a)) => r a -> RecvAction a
makeSendAction' :: (WriteableChannel w, Poisonable (w b)) => w b -> (a -> b) -> SendAction a
makeRecvAction' :: (ReadableChannel r, Poisonable (r a)) => r a -> (a -> b) -> RecvAction b
makeCustomSendAction :: (a -> CHP ()) -> CHP () -> CHP () -> SendAction a
makeCustomRecvAction :: CHP a -> CHP () -> CHP () -> RecvAction a
nullSendAction :: SendAction a
nullRecvAction :: a -> RecvAction a
Documentation
data SendAction a Source
A send action. See sendAction. Note that it is poisonable.
show/hide Instances
data RecvAction a Source
A receive action. See recvAction. Note that it is poisonable.
show/hide Instances
sendAction :: SendAction a -> a -> CHP ()Source
Sends a data item using the given sendAction. Whether this operation can be used in a choice (see alt) is entirely dependent on whether the original action could be used in an alt. For all of CHP's channels, this is true, but for your own custom send actions, probably not.
recvAction :: RecvAction a -> CHP aSource
Receives a data item using the given recvAction. Whether this operation can be used in a choice (see alt) is entirely dependent on whether the original action could be used in an alt. For all of CHP's channels, this is true, but for your own custom receive actions, probably not.
makeSendAction :: (WriteableChannel w, Poisonable (w a)) => w a -> SendAction aSource
Given a writing channel end, gives back the corresponding SendAction.
makeRecvAction :: (ReadableChannel r, Poisonable (r a)) => r a -> RecvAction aSource
Given a reading channel end, gives back the corresponding RecvAction.
makeSendAction' :: (WriteableChannel w, Poisonable (w b)) => w b -> (a -> b) -> SendAction aSource
Like makeSendAction, but always applies the given function before sending the item.
makeRecvAction' :: (ReadableChannel r, Poisonable (r a)) => r a -> (a -> b) -> RecvAction bSource
Like makeRecvAction, but always applies the given function after receiving an item.
makeCustomSendAction :: (a -> CHP ()) -> CHP () -> CHP () -> SendAction aSource
Creates a custom send operation. The first parameter should perform the send, the second parameter should poison your communication channel, and the third parameter should check whether the communication channel is already poisoned. Generally, you will want to use makeSendAction instead of this function.
makeCustomRecvAction :: CHP a -> CHP () -> CHP () -> RecvAction aSource
Creates a custom receive operation. The first parameter should perform the receive, the second parameter should poison your communication channel, and the third parameter should check whether the communication channel is already poisoned. Generally, you will want to use makeRecvAction instead of this function.
nullSendAction :: SendAction aSource
Acts like a SendAction, but just discards the data.
nullRecvAction :: a -> RecvAction aSource
Acts like a RecvAction, but always gives back the given data item.
Produced by Haddock version 2.4.2