Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Channel (m :: Type -> Type) = Channel {
- send :: ByteString -> m ()
- recv :: m (Maybe ByteString)
- createBufferConnectedChannels :: MonadSTM m => m (Channel m, Channel m)
- createPipeConnectedChannels :: IO (Channel IO, Channel IO)
- createSocketConnectedChannels :: Family -> IO (Channel IO, Channel IO)
- withFifosAsChannel :: FilePath -> FilePath -> (Channel IO -> IO a) -> IO a
- socketAsChannel :: Socket -> Channel IO
- channelEffect :: Monad m => (ByteString -> m ()) -> (Maybe ByteString -> m ()) -> Channel m -> Channel m
- delayChannel :: forall (m :: Type -> Type). MonadDelay m => DiffTime -> Channel m -> Channel m
- loggingChannel :: forall (m :: Type -> Type) id. (MonadSay m, Show id) => id -> Channel m -> Channel m
Documentation
data Channel (m :: Type -> Type) Source #
Channel | |
|
createBufferConnectedChannels :: MonadSTM m => m (Channel m, Channel m) Source #
Create a pair of Channel
s that are connected internally.
This is intended for inter-thread communication, such as between a multiplexing thread and a thread running a peer.
It uses lazy ByteString
s but it ensures that data written to the channel
is fully evaluated first. This ensures that any work to serialise the data
takes place on the writer side and not the reader side.
createPipeConnectedChannels :: IO (Channel IO, Channel IO) Source #
Create a local pipe, with both ends in this process, and expose that as
a pair of Channel
s, one for each end.
This is primarily for testing purposes since it does not allow actual IPC.
Open a pair of Unix FIFOs, and expose that as a Channel
.
The peer process needs to open the same files but the other way around, for writing and reading.
This is primarily for the purpose of demonstrations that use communication between multiple local processes. It is Unix specific.
socketAsChannel :: Socket -> Channel IO Source #
Make a Channel
from a Socket
. The socket must be a stream socket
:: Monad m | |
=> (ByteString -> m ()) | Action before |
-> (Maybe ByteString -> m ()) | Action after |
-> Channel m | |
-> Channel m |
delayChannel :: forall (m :: Type -> Type). MonadDelay m => DiffTime -> Channel m -> Channel m Source #
Delay a channel on the receiver end.
This is intended for testing, as a crude approximation of network delays. More accurate models along these lines are of course possible.