hakka-0.2.0: Minimal akka-inspired actor library

Safe HaskellNone
LanguageHaskell2010

Hakka.Actor

Contents

Synopsis

Actors

data ActorRef m Source #

Serializable handle to an Actor

Instances

Eq (ActorRef m) Source # 

Methods

(==) :: ActorRef m -> ActorRef m -> Bool #

(/=) :: ActorRef m -> ActorRef m -> Bool #

Show (ActorRef m) Source # 

Methods

showsPrec :: Int -> ActorRef m -> ShowS #

show :: ActorRef m -> String #

showList :: [ActorRef m] -> ShowS #

The ActorIO Monad

data ActorIO m a Source #

Actions which actors execute in response to a received message run within the ActorIO monad.

Instances

Monad (ActorIO m) Source # 

Methods

(>>=) :: ActorIO m a -> (a -> ActorIO m b) -> ActorIO m b #

(>>) :: ActorIO m a -> ActorIO m b -> ActorIO m b #

return :: a -> ActorIO m a #

fail :: String -> ActorIO m a #

Functor (ActorIO m) Source # 

Methods

fmap :: (a -> b) -> ActorIO m a -> ActorIO m b #

(<$) :: a -> ActorIO m b -> ActorIO m a #

Applicative (ActorIO m) Source # 

Methods

pure :: a -> ActorIO m a #

(<*>) :: ActorIO m (a -> b) -> ActorIO m a -> ActorIO m b #

(*>) :: ActorIO m a -> ActorIO m b -> ActorIO m b #

(<*) :: ActorIO m a -> ActorIO m b -> ActorIO m a #

MonadIO (ActorIO m) Source # 

Methods

liftIO :: IO a -> ActorIO m a #

noop :: ActorIO m () Source #

Empty actor action

liftIO :: MonadIO m => forall a. IO a -> m a #

Lift a computation from the IO monad.

Creating Actors

actor Source #

Arguments

:: Show m 
=> String

The name of the actor. Must be url safe and unique within the context.

-> (m -> ActorIO m ())

The message handler of the actor.

-> ActorIO m (ActorRef m)

An ActorRef referencing the actor

Create a new child actor in the current context (actor system or actor).

Sending messages

tell Source #

Arguments

:: ActorRef m

The recipient of the message

-> m

The message to send

-> ActorRef m

The sender of the message

-> ActorIO m () 

Send a message to an actor. Does not block (immediately returns control flow).

(!) Source #

Arguments

:: ActorRef m

The reference to the receiving actor

-> m

The message

-> ActorIO m () 

Like tell but the sender will be the actor which executes the action.

forward Source #

Arguments

:: ActorRef m

The reference to the receiving actor

-> m

The message

-> ActorIO m () 

Like tell but the sender will be the sender of the currently processed message.

schedule Source #

Arguments

:: Int

Delay in milliseconds before the first message gets sent.

-> Int

Delay in milliseconds between two subsequent messages

-> ActorRef m

The reference to the receiving actor (Dereferenced in the future)

-> m

The message

-> ActorIO m Cancellable 

Schedule the delivery of a message in the future

scheduleOnce Source #

Arguments

:: Int

Delay in milliseconds before the message gets sent.

-> ActorRef m

The reference to the receiving actor (Dereferenced in the future)

-> m

The message

-> ActorIO m Cancellable 

Schedule the delivery of a message in the future

Known ActorRefs

sender :: ActorIO m (ActorRef m) Source #

Obtain the reference to the sender of the currently processed message

self :: ActorIO m (ActorRef m) Source #

Obtain the reference to the actor executing the action

parent :: ActorIO m (ActorRef m) Source #

Obtain the reference to the parent of self

Logging

log Source #

Arguments

:: Severity

The severity of the log message

-> String

The message to log

-> ActorIO m () 

Log a message. Log messages will be sequentialized.

data Severity Source #

Log message severity

Constructors

Debug 
Info 
Warn 
Error 

Changing the behavior

become Source #

Arguments

:: (m -> ActorIO m ())

The new behavior

-> ActorIO m () 

Switch the behavior of the current actor

stop :: ActorIO m () Source #

Stop this actor

Actor Systems

actorSystem Source #

Arguments

:: Show m 
=> String

The name of the system. Must be url safe and unique within the process.

-> ActorIO m a

Action to initialize the system. Runs within the context of the root actor.

-> IO ActorSystem 

Create a new actor system

data ActorSystem Source #

An ActorSystem serves as the root of an actor hierarchy

terminate :: ActorSystem -> IO () Source #

Terminate the actor System

Util