Safe Haskell | None |
---|---|
Language | Haskell2010 |
Extensions | LambdaCase |
A small library for Erlang-style actor semantics, for coordinating concurrent processes and message passing
Documentation
type Process message = Pid message -> IO () Source
A process takes its own Pid, to receive messages with, and can do any IO actions
spawn :: Process message -> IO (Pid message) Source
Start up a concurrent process and get a reference to it
Process ID: the way we refer to concurrent processes.
Send messages to them with !
(!) :: Pid message -> message -> IO () Source
Send a message to another process's "mailbox."
The messages are handled with receive
Like Erlang, we ignore any messages sent to processes that have died
receive :: Pid message -> (message -> IO a) -> IO a Source
Receive data from the process's "mailbox"
If there are no messages in the mailbox, the process waits until there is one then handles it
Note at the moment we don't enforce in the type system that a process is only reading its own mailbox, but that's the idiom in Erlang (1 mailbox per process)
runNanoErl :: IO a -> IO a Source
Put this at the toplevel of your program, e.g.
main = runNanoErl $ ...
To ensure that your program doesn't exit before all its
spawn
ed processes have finished running