Trait crossbus::actor::Actor

source ·
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§

source

fn create(ctx: &mut Context<Self>) -> Self

create a instance of an actor

source

fn action(&mut self, msg: Self::Message, ctx: &mut Context<Self>)

make a reaction when the message comes called when the actor received message

Provided Methods§

source

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

source

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
source

fn started(&mut self, _: &mut Context<Self>)

called when the actor starts but not running

source

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

source

fn aborted(&mut self, _: &mut Context<Self>)

called when the actor get aborted

source

fn stopped(&mut self, _: &mut Context<Self>)

called when the actor is stopping but not to exit the actor can restore running state from stopped state

source

fn close(&mut self, ctx: &mut Context<Self>)

final work before exit it will be called even the actor gets aborted after this, the actor is terminated

even if the actor state is changed after executing it it is ignored though anyway the actor will respond to state change before Actor::close

Implementors§