agner_actors/
exit_handler.rs1use std::fmt;
2
3use agner_utils::std_error_pp::StdErrorPP;
4
5use crate::actor_id::ActorID;
6use crate::exit::{Exit, Shutdown, WellKnown};
7
8pub trait ExitHandler: fmt::Debug + Send + Sync + 'static {
14 fn on_actor_exit(&self, actor_id: ActorID, exit: Exit);
15}
16
17#[derive(Debug, Clone, Copy)]
19pub struct LogExitHandler;
20
21#[derive(Debug, Clone, Copy)]
23pub struct NoopExitHandler;
24
25impl ExitHandler for LogExitHandler {
26 fn on_actor_exit(&self, actor_id: ActorID, exit: Exit) {
27 match exit {
28 Exit::Standard(WellKnown::Normal | WellKnown::Shutdown(Shutdown(None))) => (),
29 Exit::Standard(WellKnown::Linked(offender, reason)) => {
30 tracing::warn!("[{}] linked {} exited: {}", actor_id, offender, reason.pp());
31 },
32 failure => {
33 tracing::error!("[{}] {}", actor_id, failure.pp())
34 },
35 }
36 }
37}
38
39impl ExitHandler for NoopExitHandler {
40 fn on_actor_exit(&self, _actor_id: ActorID, _exit: Exit) {}
41}