Reference

ActorInterfaces.ClassicModule
module ActorInterfaces.Classic

The Classic model is the one described by Gul Agha in the book "ACTORS: A Model of Concurrent Computation in Distributed Systems"

An actor is spawned from a behavior (a function or other callable object), incoming messages will be dispatched to it. While handling the message, the behavior can use the primitives send, spawn, become and self.

A so-called context will also be provided by the runtime to the behavior, in the keyword argument ctx. It must be forwarded to the primitives, helping the runtime to manage actors without having global state. The macro @ctx does this forwarding automatically.

Note on async and blocking: @async is allowed in actor code, but async code should not operate directly on the actor state, only through messages. Blocking operations will also work inside onmessage, but in the Classic model it is up to the implementation to provide any or no concurrency of blocked actors, so blocking should generally be avoided if possible.

Examples

using ActorInterfaces.Classic

mutable struct Counter
    counter::Int
end

struct Increment end

@ctx function (me::Counter)(msg::Increment)
    me.counter += 1
end
source
ActorInterfaces.Classic.becomeFunction
become(behavior; ctx)
become(behavior, aquintances...; ctx)

Replace the current actor behavior with the given behavior and optionally arguments aquintances to it.

The new behavior will be effective at the processing of the next message.

The ctx argument can be automatically injected by @ctx.

See also spawn.

source
ActorInterfaces.Classic.sendFunction
send(recipient::Addr, msg...; ctx)

Send the message msg to a recipient actor address.

It is possible to send multiple arguments as a single message.

The ctx argument can be automatically injected by @ctx.

source
ActorInterfaces.Classic.spawnFunction
spawn(behavior; ctx) :: Addr
spawn(behavior, aquintances...; ctx) :: Addr

Create a new actor with the given behavior and optionally arguments aquintances to it.

behavior can be any callable object (function, closure or functor).

If aquintances are given, they will be stored and later provided with every incoming message to the behavior (as the first arguments to the call, before the message), simulating state in a functional style.

If behavior is a functor, it can store its state inside, without externally given aquintances (called the OOP style).

The returned address can be used to send messages to the newly created actor. The actor itself is not accessible directly.

The ctx argument can be automatically injected by @ctx.

source
ActorInterfaces.Classic.@ctxMacro
@ctx

Inject the actor context into onmessage methods automatically.

The "actor context" allows the runtime to identify the current actor efficiently. It is passed to onmessage and must be provided to every actor primitive call. It can either be handled explicitly by the user or implicitly by the @ctx macro.

When an onmessage method definition is marked with @ctx, calls to send, spawn, etc. from it need not to handle the ctx argument, it will be injected by the macro.

source