unliftio-messagebox-1.0.2: Fast and robust message queues for concurrent processes
Safe HaskellNone
LanguageHaskell2010

UnliftIO.MessageBox.Class

Description

This module contains a type class that describes exchangable operations on messages boxes.

Synopsis

Documentation

class (IsMessageBox (MessageBox cfg), IsInput (Input (MessageBox cfg))) => IsMessageBoxFactory cfg where Source #

Create IsMessageBox instances from a parameter. Types that determine MessageBox values.

For a limited message box this might be the limit of the message queue.

Associated Types

type MessageBox cfg :: Type -> Type Source #

Methods

getConfiguredMessageLimit :: cfg -> Maybe Int Source #

Return a message limit.

NOTE: This method was added for unit tests. Although the method is totally valid, it might not be super useful in production code. Also note that the naming follows the rule: Reserve short names for entities that are used often.

newMessageBox :: MonadUnliftIO m => cfg -> m (MessageBox cfg a) Source #

Create a new msgBox. This is required to receive a message. NOTE: Only one process may receive on an msgBox.

Instances

Instances details
IsMessageBoxFactory BlockingUnlimited Source # 
Instance details

Defined in UnliftIO.MessageBox.Unlimited

Associated Types

type MessageBox BlockingUnlimited :: Type -> Type Source #

IsMessageBoxFactory WaitingBoxLimit Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Associated Types

type MessageBox WaitingBoxLimit :: Type -> Type Source #

IsMessageBoxFactory NonBlockingBoxLimit Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Associated Types

type MessageBox NonBlockingBoxLimit :: Type -> Type Source #

IsMessageBoxFactory BlockingBoxLimit Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Associated Types

type MessageBox BlockingBoxLimit :: Type -> Type Source #

IsMessageBoxFactory cfg => IsMessageBoxFactory (CatchAllFactory cfg) Source # 
Instance details

Defined in UnliftIO.MessageBox.CatchAll

Associated Types

type MessageBox (CatchAllFactory cfg) :: Type -> Type Source #

class IsInput (Input msgBox) => IsMessageBox msgBox where Source #

A type class for msgBox types. A common interface for receiving messages.

Minimal complete definition

receive, tryReceive, newInput

Associated Types

type Input msgBox :: Type -> Type Source #

Type of the corresponding input

Methods

receive :: MonadUnliftIO m => msgBox a -> m (Maybe a) Source #

Receive a message. Take whatever time it takes. Return Just the value or Nothing when an error occurred.

NOTE: Nothing may sporadically be returned, especially when there is a lot of load, so please make sure to build your application in such a way, that it anticipates failure.

tryReceive :: MonadUnliftIO m => msgBox a -> m (Future a) Source #

Return a Future that can be used to wait for the arrival of the next message. NOTE: Each future value represents the next slot in the queue so one future corresponds to exactly that message (should it arrive) and if that future value is dropped, that message will be lost!

receiveAfter Source #

Arguments

:: MonadUnliftIO m 
=> msgBox a

Message box

-> Int

Time in micro seconds to wait until the action is invoked.

-> m (Maybe a) 

Wait for an incoming message or return Nothing.

The default implementation uses tryReceive to get a Future on which awaitFuture inside a timeout is called.

Instances might override this with more performant implementations especially non-blocking Unagi channel based implementation.

NOTE: Nothing may sporadically be returned, especially when there is a lot of load, so please make sure to build your application in such a way, that it anticipates failure.

newInput :: MonadUnliftIO m => msgBox a -> m (Input msgBox a) Source #

Create a new input that enqueus messages, which are received by the msgBox

Instances

Instances details
IsMessageBox UnlimitedBox Source #

A blocking instance that invokes receive.

Instance details

Defined in UnliftIO.MessageBox.Unlimited

Associated Types

type Input UnlimitedBox :: Type -> Type Source #

IsMessageBox WaitingBox Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Associated Types

type Input WaitingBox :: Type -> Type Source #

IsMessageBox NonBlockingBox Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Associated Types

type Input NonBlockingBox :: Type -> Type Source #

IsMessageBox BlockingBox Source #

A blocking instance that invokes receive.

Instance details

Defined in UnliftIO.MessageBox.Limited

Associated Types

type Input BlockingBox :: Type -> Type Source #

IsMessageBox box => IsMessageBox (CatchAllBox box) Source # 
Instance details

Defined in UnliftIO.MessageBox.CatchAll

Associated Types

type Input (CatchAllBox box) :: Type -> Type Source #

class IsInput input where Source #

A type class for input types. A common interface for delivering messages.

Methods

deliver :: MonadUnliftIO m => input a -> a -> m Bool Source #

Send a message. Take whatever time it takes. Depending on the implementation, this might be a non-blocking operation. Return if the operation was successful.

NOTE: False may sporadically be returned, especially when there is a lot of load, so please make sure to build your application in such a way, that it anticipates failure.

Instances

Instances details
IsInput UnlimitedBoxInput Source #

A blocking instance that invokes deliver.

Instance details

Defined in UnliftIO.MessageBox.Unlimited

Methods

deliver :: MonadUnliftIO m => UnlimitedBoxInput a -> a -> m Bool Source #

IsInput WaitingInput Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Methods

deliver :: MonadUnliftIO m => WaitingInput a -> a -> m Bool Source #

IsInput NonBlockingInput Source # 
Instance details

Defined in UnliftIO.MessageBox.Limited

Methods

deliver :: MonadUnliftIO m => NonBlockingInput a -> a -> m Bool Source #

IsInput BlockingInput Source #

A blocking instance that invokes deliver.

Instance details

Defined in UnliftIO.MessageBox.Limited

Methods

deliver :: MonadUnliftIO m => BlockingInput a -> a -> m Bool Source #

IsInput i => IsInput (CatchAllInput i) Source # 
Instance details

Defined in UnliftIO.MessageBox.CatchAll

Methods

deliver :: MonadUnliftIO m => CatchAllInput i a -> a -> m Bool Source #

handleMessage :: (MonadUnliftIO m, IsMessageBox msgBox) => msgBox message -> (message -> m b) -> m (Maybe b) Source #

Receive a message and apply a function to it.