pub trait Actor: Sized + Unpin + 'static {
type Message: Message;
// Required methods
fn create(ctx: &mut Context<Self>) -> Self;
fn action(&mut self, msg: Self::Message, ctx: &mut Context<Self>);
// Provided methods
fn initial(&mut self, _: &mut Context<Self>) { ... }
fn start() -> (Addr<Self::Message>, ActorId) { ... }
fn started(&mut self, _: &mut Context<Self>) { ... }
fn state(&mut self, _: &mut Context<Self>) -> ActingState { ... }
fn aborted(&mut self, _: &mut Context<Self>) { ... }
fn stopped(&mut self, _: &mut Context<Self>) { ... }
fn close(&mut self, ctx: &mut Context<Self>) { ... }
}
Expand description
An abstraction for a computational entity
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn initial(&mut self, _: &mut Context<Self>)
fn initial(&mut self, _: &mut Context<Self>)
preparation before start the actor
it get executed before Actor::state
gets called. That means it is called even
Actor::state
return ActingState::Abort
even if the actor state is changed after executing it it is ignored though anyway the actor should step into Started state for this state change
sourcefn start() -> (Addr<Self::Message>, ActorId)
fn start() -> (Addr<Self::Message>, ActorId)
start the actor it basically does the following things:
- Create the default context
- Create the actor instance
- consume the Actor to Create an ActorRegister
- Register the Actor and return the ActorGuard
- Invoke ContextRunner to run the actor
sourcefn state(&mut self, _: &mut Context<Self>) -> ActingState
fn state(&mut self, _: &mut Context<Self>) -> ActingState
to decide whether to resume/stop/continue the actor
the actor will step into Stopping
phase if Stop
is returned
and actor will be stopped if Resume
is not returned
when it is in stopping phase
Real-Time control or more elaborated execution could be achieved right here