Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Channel (m :: Type -> Type) a = Channel {}
- isoKleisliChannel :: forall a b m. Monad m => (a -> m b) -> (b -> m a) -> Channel m a -> Channel m b
- hoistChannel :: (forall x. m x -> n x) -> Channel m a -> Channel n a
- channelEffect :: Monad m => (a -> m ()) -> (Maybe a -> m ()) -> Channel m a -> Channel m a
- delayChannel :: forall (m :: Type -> Type) a. MonadDelay m => DiffTime -> Channel m a -> Channel m a
- loggingChannel :: forall (m :: Type -> Type) id a. (MonadSay m, Show id, Show a) => id -> Channel m a -> Channel m a
- mvarsAsChannel :: forall (m :: Type -> Type) a. MonadSTM m => StrictTMVar m a -> StrictTMVar m a -> Channel m a
- createConnectedChannels :: MonadSTM m => m (Channel m a, Channel m a)
- type ByteChannel (m :: Type -> Type) = Channel m ByteString
- handlesAsChannel :: Handle -> Handle -> Channel IO ByteString
- withFifosAsChannel :: FilePath -> FilePath -> (ByteChannel IO -> IO a) -> IO a
- socketAsChannel :: Socket -> ByteChannel IO
- createBufferConnectedChannels :: MonadSTM m => m (ByteChannel m, ByteChannel m)
- createPipeConnectedChannels :: IO (ByteChannel IO, ByteChannel IO)
- createSocketConnectedChannels :: Family -> IO (ByteChannel IO, ByteChannel IO)
Channel
data Channel (m :: Type -> Type) a Source #
A channel which can send and receive values.
It is more general than what `network-mux` requires, see ByteChannel
instead. However this is useful for testing purposes when one is either
using mux
or connecting two ends directly.
Channel | |
|
Channel API
isoKleisliChannel :: forall a b m. Monad m => (a -> m b) -> (b -> m a) -> Channel m a -> Channel m b Source #
hoistChannel :: (forall x. m x -> n x) -> Channel m a -> Channel n a Source #
delayChannel :: forall (m :: Type -> Type) a. MonadDelay m => DiffTime -> Channel m a -> Channel m a 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.
loggingChannel :: forall (m :: Type -> Type) id a. (MonadSay m, Show id, Show a) => id -> Channel m a -> Channel m a Source #
Channel which logs sent and received messages.
create a Channel
mvarsAsChannel :: forall (m :: Type -> Type) a. MonadSTM m => StrictTMVar m a -> StrictTMVar m a -> Channel m a Source #
connected Channel
s
createConnectedChannels :: MonadSTM m => m (Channel m a, Channel m a) Source #
Create a pair of channels that are connected via one-place buffers.
This is primarily useful for testing protocols.
ByteChannel
type ByteChannel (m :: Type -> Type) = Channel m ByteString Source #
Channel using ByteString
.
create a ByteChannel
:: Handle | Read handle |
-> Handle | Write handle |
-> Channel IO ByteString |
Make a Channel
from a pair of IO Handle
s, one for reading and one
for writing.
The Handles should be open in the appropriate read or write mode, and in binary mode. Writes are flushed after each write, so it is safe to use a buffering mode.
For bidirectional handles it is safe to pass the same handle for both.
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 -> ByteChannel IO Source #
Make a Channel
from a Socket
. The socket must be a stream socket
connected ByteChannel
s
createBufferConnectedChannels :: MonadSTM m => m (ByteChannel m, ByteChannel 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 (ByteChannel IO, ByteChannel 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.
createSocketConnectedChannels Source #
:: Family | Usually AF_UNIX or AF_INET |
-> IO (ByteChannel IO, ByteChannel IO) |