Safe Haskell | None |
---|---|
Language | Haskell2010 |
Thread safe queues for uni directional message passing between threads.
This message box has an upper limit, that means that sometimes delivery either fails or is blocked until the receiving thread has consumed more messages.
Use this module if the producer(s) outperform the consumer,
but you want the extra safety that the queue blocks the
Input
after a certain message limit is reached.
If you are sure that the producers fire at a slower rate then the rate at which the consumer consumes messages, use this module.
Synopsis
- data MessageLimit
- messageLimitToInt :: MessageLimit -> Int
- newtype BlockingBoxLimit = BlockingBoxLimit MessageLimit
- data BlockingBox a
- data BlockingInput a
- newtype NonBlockingBoxLimit = NonBlockingBoxLimit MessageLimit
- data NonBlockingBox a
- newtype NonBlockingInput a = NonBlockingInput (BlockingInput a)
- data WaitingBoxLimit = WaitingBoxLimit !(Maybe Int) !Int !MessageLimit
- data WaitingBox a = WaitingBox WaitingBoxLimit (BlockingBox a)
- data WaitingInput a = WaitingInput !Int !(BlockingInput a)
Documentation
data MessageLimit Source #
Message Limit
The message limit must be a reasonable small positive integer that is also a power of two. This stems from the fact that Unagi is used under the hood.
The limit is a lower bound.
Instances
messageLimitToInt :: MessageLimit -> Int Source #
Convert a MessageLimit
to the
Int
representation.
newtype BlockingBoxLimit Source #
Contains the (vague) limit of messages that a BlockingBox
can buffer, i.e. that deliver
can put into a BlockingInput
of a BlockingBox
.
Instances
data BlockingBox a Source #
A message queue out of which messages can by receive
d.
This is the counter part of Input
. Can be used for reading
messages.
Messages can be received by receive
or tryReceive
.
Instances
IsMessageBox BlockingBox Source # | A blocking instance that invokes |
Defined in UnliftIO.MessageBox.Limited receive :: MonadUnliftIO m => BlockingBox a -> m (Maybe a) Source # tryReceive :: MonadUnliftIO m => BlockingBox a -> m (Future a) Source # receiveAfter :: MonadUnliftIO m => BlockingBox a -> Int -> m (Maybe a) Source # newInput :: MonadUnliftIO m => BlockingBox a -> m (Input BlockingBox a) Source # | |
type Input BlockingBox Source # | |
Defined in UnliftIO.MessageBox.Limited |
data BlockingInput a Source #
A message queue into which messages can be enqued by,
e.g. tryToDeliver
.
Messages can be received from an BlockingBox
.
The Input
is the counter part of a BlockingBox
.
Instances
IsInput BlockingInput Source # | A blocking instance that invokes |
Defined in UnliftIO.MessageBox.Limited deliver :: MonadUnliftIO m => BlockingInput a -> a -> m Bool Source # deliver_ :: MonadUnliftIO m => BlockingInput a -> a -> m () Source # |
newtype NonBlockingBoxLimit Source #
A BlockingBoxLimit
wrapper for non-blocking IsMessageBoxArg
instances.
Instances
data NonBlockingBox a Source #
A BlockingBox
wrapper for non-blocking IsMessageBox
instances.
The difference to the BlockingBox
instance is that deliver
immediately returns if the message box limit is surpassed.
Instances
IsMessageBox NonBlockingBox Source # | |
Defined in UnliftIO.MessageBox.Limited receive :: MonadUnliftIO m => NonBlockingBox a -> m (Maybe a) Source # tryReceive :: MonadUnliftIO m => NonBlockingBox a -> m (Future a) Source # receiveAfter :: MonadUnliftIO m => NonBlockingBox a -> Int -> m (Maybe a) Source # newInput :: MonadUnliftIO m => NonBlockingBox a -> m (Input NonBlockingBox a) Source # | |
type Input NonBlockingBox Source # | |
Defined in UnliftIO.MessageBox.Limited |
newtype NonBlockingInput a Source #
A wrapper around BlockingInput
with a non-blocking IsInput
instance.
deliver
will enqueue the message or return False
immediately,
if the message box already contains more messages than
it's limit allows.
Instances
IsInput NonBlockingInput Source # | |
Defined in UnliftIO.MessageBox.Limited deliver :: MonadUnliftIO m => NonBlockingInput a -> a -> m Bool Source # deliver_ :: MonadUnliftIO m => NonBlockingInput a -> a -> m () Source # |
data WaitingBoxLimit Source #
A IsMessageBoxArg
instance wrapping the BlockingBox
with independently configurable timeouts for receive
and deliver
.
Instances
data WaitingBox a Source #
A BlockingBox
an a WaitingBoxLimit
for
the IsMessageBox
instance.
Instances
IsMessageBox WaitingBox Source # | |
Defined in UnliftIO.MessageBox.Limited receive :: MonadUnliftIO m => WaitingBox a -> m (Maybe a) Source # tryReceive :: MonadUnliftIO m => WaitingBox a -> m (Future a) Source # receiveAfter :: MonadUnliftIO m => WaitingBox a -> Int -> m (Maybe a) Source # newInput :: MonadUnliftIO m => WaitingBox a -> m (Input WaitingBox a) Source # | |
type Input WaitingBox Source # | |
Defined in UnliftIO.MessageBox.Limited |
data WaitingInput a Source #
An input for a BlockingBox
that will block
for not much more than the given timeout when
the message box is full.
WaitingInput !Int !(BlockingInput a) |
Instances
IsInput WaitingInput Source # | |
Defined in UnliftIO.MessageBox.Limited deliver :: MonadUnliftIO m => WaitingInput a -> a -> m Bool Source # deliver_ :: MonadUnliftIO m => WaitingInput a -> a -> m () Source # |