use async_trait::async_trait;
use crate::{Actor, ActorContext, ActorExitStatus, Handler};
#[derive(Debug)]
pub enum Command {
Pause,
Resume,
ExitWithSuccess,
Quit,
Nudge,
}
#[async_trait]
impl<A: Actor> Handler<Command> for A {
type Reply = ();
async fn handle(
&mut self,
command: Command,
ctx: &ActorContext<Self>,
) -> Result<Self::Reply, ActorExitStatus> {
match command {
Command::Pause => {
ctx.pause();
Ok(())
}
Command::ExitWithSuccess => Err(ActorExitStatus::Success),
Command::Quit => Err(ActorExitStatus::Quit),
Command::Nudge => Ok(()),
Command::Resume => {
ctx.resume();
Ok(())
}
}
}
}
#[derive(Debug)]
pub(crate) struct Observe;
#[async_trait]
impl<A: Actor> Handler<Observe> for A {
type Reply = A::ObservableState;
async fn handle(
&mut self,
_observe: Observe,
ctx: &ActorContext<Self>,
) -> Result<Self::Reply, ActorExitStatus> {
Ok(ctx.observe(self))
}
}