Implementation of the actor model on top of the GHC's concurrency.
The API mimics Erlang's concurrency primitives, with slight differences.
- type Process = ThreadId
- self :: IO Process
- kill :: IO Process -> IO ()
- exit :: IO ()
- sleep :: Int -> IO ()
- wait :: IO ()
- say :: String -> IO ()
- type MBox m = TChan m
- data Actor m = Actor {}
- actor :: t -> (t -> MBox m -> IO a) -> IO (Actor m)
- spawn :: (MBox m -> IO a) -> IO (Actor m)
- receive :: MBox m -> (m -> IO a) -> IO b
- (?) :: MBox m -> (m -> IO a) -> IO b
- (<?) :: IO (MBox m) -> (m -> IO a) -> IO b
- send :: Actor m -> m -> IO m
- (!) :: Actor m -> m -> IO m
- (<!) :: IO (Actor m) -> m -> IO m
- (!>) :: Actor m -> IO m -> IO m
- (<!>) :: IO (Actor m) -> IO m -> IO m
- spawn_receive :: (m -> IO a) -> IO (Actor m)
- on_exception :: IO a -> IO a -> IO a
- tolerant :: IO a -> IO a
- faultable :: IO () -> IO ()
Processes
Perform non busy waiting for a given number of microseconds in the current process.
The message box
Actors
The actor is a process associated with the message box.
Note that the actor is parameterized by the type of message that it can accept.
actor :: t -> (t -> MBox m -> IO a) -> IO (Actor m)Source
Create a new actor from a function, send the initial argument and the message box to this actor via function arguments.
This function calls forkIO
.
spawn :: (MBox m -> IO a) -> IO (Actor m)Source
Create a new actor from a function, send the message box to this actor via function argument.
This function calls forkIO
.
Messages
(<!>) :: IO (Actor m) -> IO m -> IO mSource
Variant of (!) with the actor and the message inside the IO.
Combine actors with messages
spawn_receive :: (m -> IO a) -> IO (Actor m)Source
Create a new receiving actor.
This function calls forkIO
.
Fault tolerance
on_exception :: IO a -> IO a -> IO aSource
Perform an action, on exceptions perform a given action f
.