This module provides a *very* basic support for processes with message queues. It was built using channels and MVars.
- data ReceiverT r m a
- data Handle r
- type Process r = ReceiverT r IO
- makeProcess :: (m t -> IO s) -> ReceiverT r m t -> Process r s
- runHere :: MonadIO m => Process r t -> m t
- spawn :: MonadIO m => Process r k -> m (Handle r)
- kill :: MonadIO m => Handle a -> m ()
- self :: Monad m => ReceiverT r m (Handle r)
- sendTo :: MonadIO m => Handle a -> a -> m ()
- recv :: MonadIO m => ReceiverT r m r
- sendRecv :: MonadIO m => Handle a -> a -> ReceiverT r m r
Types
The ReceiverT generic type.
r
- the type of things the process will receive
m
- the monad in which it will run
a
- the classic monad parameter
MonadReader r m => MonadReader r (ReceiverT r m) | |
MonadState s m => MonadState s (ReceiverT r m) | |
MonadError e m => MonadError e (ReceiverT r m) | |
(Monoid w, MonadWriter w m) => MonadWriter w (ReceiverT w m) | |
MonadTrans (ReceiverT r) | |
Monad m => Monad (ReceiverT r m) | |
MonadCatchIO m => MonadCatchIO (ReceiverT r m) | |
MonadIO m => MonadIO (ReceiverT r m) |
A Process handle. It's returned on process creation and should be used | afterwards to send messages to it
Functions
Process creation / destruction
makeProcess :: (m t -> IO s) -> ReceiverT r m t -> Process r sSource
makeProcess builds a process from a code that generates an IO action. Usage:
process <- makeProcess evalFunction receiver
runHere executes process code in the current environment. Usage:
result <- runHere process
spawn starts a process and returns its handle. Usage:
handle <- spawn process
kill lets you *brutally* terminate a running process. Usage:
kill processHandle
Message passing
self :: Monad m => ReceiverT r m (Handle r)Source
self returns the handle of the current process. Usage:
handle <- self
sendTo lets you send a message to a running process. Usage:
sendTo processHandle message