Safe Haskell | None |
---|---|
Language | Haskell2010 |
The message passing effect.
This module describes an abstract message passing effect, and a process effect, mimicking Erlang's process and message semantics.
An implementation of a handler for these effects can be found in
Dispatcher
.
- newtype ProcessId = ProcessId {}
- fromProcessId :: Iso' ProcessId Int
- data Process b where
- self :: Member Process r => Eff r ProcessId
- trapExit :: Member Process r => Bool -> Eff r ()
- getTrapExit :: Member Process r => Eff r Bool
- raiseError :: Member Process r => String -> Eff r b
- catchProcessError :: forall r w. Member Process r => (String -> Eff r w) -> Eff r w -> Eff r w
- ignoreProcessError :: (HasCallStack, Member Process r) => Eff r a -> Eff r (Either String a)
- data MessagePassing b where
- SendMessage :: Typeable m => ProcessId -> m -> MessagePassing Bool
- ReceiveMessage :: forall e m. (Typeable m, Typeable (Message m)) => (m -> e) -> MessagePassing (Message e)
- data Message m where
- ProcessControlMessage :: String -> Message m
- Message :: m -> Message m
- sendMessage :: forall o r. (HasCallStack, Member MessagePassing r, Typeable o) => ProcessId -> o -> Eff r Bool
- receiveMessage :: forall o r. (HasCallStack, Member MessagePassing r, Member Process r, Typeable o) => Proxy o -> Eff r (Message o)
Documentation
Each process is identified by a single process id, that stays constant throughout the life cycle of a process. Also, message sending relies on these values to address messages to processes.
The process effect is the basis for message passing concurrency. This binds the semantics of a process with a process-id, and some process flags, and the ability to leave a process early with an error.
trapExit :: Member Process r => Bool -> Eff r () Source #
Set the flag that controls a process reaction to exit messages from linked/monitored processes.
raiseError :: Member Process r => String -> Eff r b Source #
Thrown an error, can be caught by catchProcessError
.
catchProcessError :: forall r w. Member Process r => (String -> Eff r w) -> Eff r w -> Eff r w Source #
Catch and handle an error raised by raiseError
. Works independent of the
handler implementation.
ignoreProcessError :: (HasCallStack, Member Process r) => Eff r a -> Eff r (Either String a) Source #
Like catchProcessError
it catches raiseError
, but instead of invoking a
user provided handler, the result is wrapped into an Either
.
data MessagePassing b where Source #
An effect for sending and receiving messages.
SendMessage :: Typeable m => ProcessId -> m -> MessagePassing Bool | Send a message to a process addressed by the |
ReceiveMessage :: forall e m. (Typeable m, Typeable (Message m)) => (m -> e) -> MessagePassing (Message e) | Receive a message. This should block until an a message was received. The
pure function may convert the incoming message into something, and the
result is returned as |
When a process invokes receiveMessage
a value of this type is returned.
There are more reasons that receiveMessage
might return, one is that a
message was sent to the process, another might be that in internal, handler
specific, event occurred for which the process should wake-up.
ProcessControlMessage :: String -> Message m | |
Message :: m -> Message m |
sendMessage :: forall o r. (HasCallStack, Member MessagePassing r, Typeable o) => ProcessId -> o -> Eff r Bool Source #
Send a message to a process addressed by the ProcessId
.
@see SendMessage
.
receiveMessage :: forall o r. (HasCallStack, Member MessagePassing r, Member Process r, Typeable o) => Proxy o -> Eff r (Message o) Source #
Block until a message was received. Expect a message of the type annotated
by the Proxy
.
Depending on trapExit
, this will raiseError
.
@see ReceiveMessage
.