Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Channel (m :: Type -> Type) a = Channel {}
- hoistChannel :: (forall x. m x -> n x) -> Channel m a -> Channel n a
- isoKleisliChannel :: forall a b m. Monad m => (a -> m b) -> (b -> m a) -> Channel m a -> Channel m b
- fixedInputChannel :: MonadSTM m => [a] -> m (Channel m a)
- mvarsAsChannel :: forall (m :: Type -> Type) a. MonadSTM m => TMVar m a -> TMVar m a -> Channel m a
- handlesAsChannel :: Handle -> Handle -> Channel IO ByteString
- socketAsChannel :: Socket -> Channel IO ByteString
- createConnectedChannels :: (MonadLabelledSTM m, MonadTraceSTM m, Show a) => m (Channel m a, Channel m a)
- createConnectedBufferedChannels :: MonadSTM m => Natural -> m (Channel m a, Channel m a)
- createConnectedBufferedChannelsUnbounded :: MonadSTM m => m (Channel m a, Channel m a)
- createPipelineTestChannels :: MonadSTM m => Natural -> m (Channel m a, Channel m 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
Documentation
data Channel (m :: Type -> Type) a Source #
One end of a duplex channel. It is a reliable, ordered channel of some medium. The medium does not imply message boundaries, it can be just bytes.
Channel | |
|
hoistChannel :: (forall x. m x -> n x) -> Channel m a -> Channel n a Source #
isoKleisliChannel :: forall a b m. Monad m => (a -> m b) -> (b -> m a) -> Channel m a -> Channel m b Source #
fixedInputChannel :: MonadSTM m => [a] -> m (Channel m a) Source #
A Channel
with a fixed input, and where all output is discarded.
The input is guaranteed to be supplied via read
with the given chunk
boundaries.
This is only useful for testing. In particular the fixed chunk boundaries can be used to test that framing and other codecs work with any possible chunking.
mvarsAsChannel :: forall (m :: Type -> Type) a. MonadSTM m => TMVar m a -> TMVar m a -> Channel m a Source #
:: 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. On unix named pipes can be used, see
prop_namedPipePipelined_IO
For bidirectional handles it is safe to pass the same handle for both.
socketAsChannel :: Socket -> Channel IO ByteString Source #
createConnectedChannels :: (MonadLabelledSTM m, MonadTraceSTM m, Show a) => 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.
createConnectedBufferedChannels :: MonadSTM m => Natural -> m (Channel m a, Channel m a) Source #
Create a pair of channels that are connected via N-place buffers.
This variant blocks when send
would exceed the maximum buffer size.
Use this variant when you want the environment rather than the Peer
to
limit the pipelining.
This is primarily useful for testing protocols.
createConnectedBufferedChannelsUnbounded :: MonadSTM m => m (Channel m a, Channel m a) Source #
Create a pair of channels that are connected via two unbounded buffers.
This is primarily useful for testing protocols.
createPipelineTestChannels :: MonadSTM m => Natural -> m (Channel m a, Channel m a) Source #
Create a pair of channels that are connected via N-place buffers.
This variant fails when send
would exceed the maximum buffer size.
Use this variant when you want the Peer
to limit the pipelining itself,
and you want to check that it does not exceed the expected level of
pipelining.
This is primarily useful for testing protocols.
:: Monad m | |
=> (a -> m ()) | Action before |
-> (Maybe a -> m ()) | Action after |
-> Channel m a | |
-> Channel m a |
Transform a channel to add an extra action before every send and after every receive.
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.