agner — processes actors.
Note: Right now this is a research project, i.e. it is possible that the API will undergo incompatible changes within the version 0.3.x.
As it has been stated, agner is inspired by Erlang/OTP, so all similarities to the actual frameworks, supported or obsolete, are purely intentional. :)
Actors
An actor is an activity with the following properties:
- runs in parallel (implemented as a
Future); - has a handle (
ActorID); - can receive messages;
- when terminates — yields an exit reason (
Exit); - any two actors can be linked with each other:
- if one of the linked actors exits with a reason other than
Exit::normal()— the other receives an exit-signal; - if the process receiving an exit-signal does not "trap exits", it will also be terminated.
- if one of the linked actors exits with a reason other than
Implementing an Actor
The actor's behaviour is defined by:
- the type of its argument;
- the type of the message it accepts;
- the behaviour function.
In order to implement an actor one should define an async function that
- returns a value for which the trait
Into<Exit>is defined - and accepts two arguments:
- a mutable reference to
Context<Message>; Argument.
- a mutable reference to
Example:
use ;
async
Spawning an Actor
Actors cannot run on their own, they need an actor system to be spawned
in. This is necessary to avoid having a global state imposed by mere usage of the library.
A System is a scope within which the actors run.
Example:
use ;
async
async
Terminating an Actor
"Willful" Termination
Returning from the Behaviour Function
If the actor's behaviour function returns — the actor terminates.
The return type of the behaviour function must implement the trait
Into<Exit>.
Example:
use Infallible;
use ;
async
async
Invoking Context::exit
Example:
use Infallible;
use ;
async
Terminating from Outside
An actor can be terminated by invoking System::exit(&self, ActorID, Exit).
In this case an actor receives an exit-signal. If the actor "traps
exits", it can perform a graceful shutdown (or even keep
running). That is if the exit reason is not Exit::kill(): in this
case the actor just terminates, and its linked actors in their turn receive exit-signals.
Supervision
As this whole project is based on the Erlang/OTP, it should not be a surprise that there are some (quite a lot of) similarities to the OTP Design Principles, namely:
Design Principles
Starting and Stopping
TBD:
Uniform Supervisor
TBD:
Mixed Supervisor
TBD:
Introspection
TBD:
Testing
TBD: