hactors-0.0.3.1: Practical actors for Haskell.

Control.Concurrent.Actor

Contents

Description

Implementation of the actor model on top of the GHC's concurrency.

The API mimics Erlang's concurrency primitives, with slight differences.

Synopsis

Processes

type Process = ThreadIdSource

The process is a VM's thread.

self :: IO ProcessSource

Get the current process.

kill :: IO Process -> IO ()Source

Kill the process.

exit :: IO ()Source

Finish the current process.

sleep :: Int -> IO ()Source

Perform non busy waiting for a given number of microseconds in the current process.

wait :: IO ()Source

Perform an infinite non busy waiting in the current process.

say :: String -> IO ()Source

Print string to stdout with the current process ID prefix.

The message box

type MBox m = TChan mSource

The message box is represented by the STM's channel.

Actors

data Actor m Source

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.

Constructors

Actor 

Fields

proc :: Process

Actor's process (a thread).

mbox :: MBox m

Actor's message box (a channel).

Instances

Eq (Actor m) 
Ord (Actor m) 
Show (Actor m) 

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

receive :: MBox m -> (m -> IO a) -> IO bSource

Wait for an asynchronous message in the message box.

(?) :: MBox m -> (m -> IO a) -> IO bSource

Infix variant of receive.

(<?) :: IO (MBox m) -> (m -> IO a) -> IO bSource

Variant of (?) with the message box inside the IO.

send :: Actor m -> m -> IO mSource

Send a message to the actor.

(!) :: Actor m -> m -> IO mSource

Infix variant of send.

(<!) :: IO (Actor m) -> m -> IO mSource

Variant of (!) with the actor inside the IO.

(!>) :: Actor m -> IO m -> IO mSource

Variant of (!) with the message inside the IO.

(<!>) :: 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.

tolerant :: IO a -> IO aSource

Perform an action ignoring any exceptions in it.

faultable :: IO () -> IO ()Source

Perform an action, do exit on exceptions.

XXX Bad name?