-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Lightweight Erlang-style actors for Haskell. -- -- This is a fork of Thespian, a library which aims to provide -- lightweight Erlang-style actors for Haskell. @package hactor @version 0.1.0.0 -- | This module implements Erlang-style actors (what Erlang calls -- processes). It does not implement network distribution (yet?). Here is -- an example: -- --
--   act1 :: Actor
--   act1 = do
--       me <- self
--       liftIO $ print act1 started
--       forever $ receive
--         [ Case $ ((n, a) :: (Int, Address)) ->
--               if n > 10000
--                   then do
--                       liftIO . throwIO $ NonTermination
--                   else do
--                       liftIO . putStrLn $ act1 got  ++ (show n) ++  from  ++ (show a)
--                       send a (n+1, me)
--         , Case $ (e :: RemoteException) ->
--               liftIO . print $ act1 received a remote exception
--         , Default $ liftIO . print $ act1: received a malformed message
--         ]
--   
--   act2 :: Address -> Actor
--   act2 addr = do
--       monitor addr
--       -- setFlag TrapRemoteExceptions
--       me <- self
--       send addr (0 :: Int, me)
--       forever $ receive
--         [ Case $ ((n, a) :: (Int, Address)) -> do
--                       liftIO . putStrLn $ act2 got  ++ (show n) ++  from  ++ (show a)
--                       send a (n+1, me)
--         , Case $ (e :: RemoteException) ->
--               liftIO . print $ act2 received a remote exception:  ++ (show e)
--         ]
--   
--   act3 :: Address -> Actor
--   act3 addr = do
--       monitor addr
--       setFlag TrapRemoteExceptions
--       forever $ receive
--         [ Case $ (e :: RemoteException) ->
--               liftIO . print $ act3 received a remote exception:  ++ (show e)
--         ]
--   
--   main = do
--       addr1 <- spawn act1
--       addr2 <- spawn (act2 addr1)
--       spawn (act3 addr2)
--       threadDelay 20000000
--   
module Control.Concurrent.Actor -- | The address of an actor, used to send messages data Address data Handler Case :: (m -> ActorM ()) -> Handler Default :: (ActorM ()) -> Handler -- | The actor monad, just a reader monad on top of IO. type ActorM = ReaderT Context IO -- | The type of an actor. It is just a monadic action in the ActorM -- monad, returning () type Actor = ActorM () data ActorException -- | Exception raised by an actor on exit data ActorExit data Flag TrapActorExceptions :: Flag -- | Sends a message from inside the ActorM monad send :: Typeable m => Address -> m -> ActorM () -- | Used to obtain an actor's own address inside the actor self :: ActorM Address -- | Try to handle a message using a list of handlers. The first handler -- matching the type of the message is used. receive :: [Handler] -> ActorM () -- | Same as receive, but times out after a specified amount of time and -- runs a default action receiveWithTimeout :: Int -> [Handler] -> ActorM () -> ActorM () -- | Spawn a new actor with default flags on a separate thread. spawn :: Actor -> IO Address -- | Run the given actor with default flags on the current thread. This can -- be useful for your program's main actor. runActor :: Actor -> IO () -- | Monitors the actor at the specified address. If an exception is raised -- in the monitored actor's thread, it is wrapped in an -- ActorException and forwarded to the monitoring actor. If the -- monitored actor terminates, an ActorException is raised in the -- monitoring Actor monitor :: Address -> ActorM () -- | Like monitor, but bi-directional link :: Address -> ActorM () -- | Kill the actor at the specified address kill :: Address -> ActorM () -- | The current status of an actor status :: Address -> ActorM ThreadStatus -- | Sets the specified flag in the actor's environment setFlag :: Flag -> ActorM () -- | Clears the specified flag in the actor's environment clearFlag :: Flag -> ActorM () -- | Toggles the specified flag in the actor's environment toggleFlag :: Flag -> ActorM () -- | Checks if the specified flag is set in the actor's environment testFlag :: Flag -> ActorM Bool instance Typeable ActorExit instance Typeable Message instance Typeable Address instance Typeable Context instance Typeable ActorException instance Show ActorExit instance Eq Flag instance Enum Flag instance Show ActorException instance Ord Address instance Eq Address instance Show Address instance Show Message instance Exception ActorException instance Exception ActorExit