mm1_node/runtime/runnable/
actor_exit.rs

1use std::future::Future;
2
3use mm1_common::types::{AnyError, Never};
4use mm1_core::context::Quit;
5
6use crate::runtime::runnable::ActorExit;
7
8impl<Ctx> ActorExit<Ctx> for Never
9where
10    Ctx: Send,
11{
12    async fn exit(self, _context: &mut Ctx) -> Never {
13        unreachable!("it's an empty type")
14    }
15}
16
17impl<Ctx> ActorExit<Ctx> for ()
18where
19    Ctx: Quit,
20{
21    fn exit(self, context: &mut Ctx) -> impl Future<Output = Never> + '_ {
22        context.quit_ok()
23    }
24}
25
26impl<Ctx, E> ActorExit<Ctx> for Result<(), E>
27where
28    E: Into<AnyError> + Send + Sync + 'static,
29    Ctx: Quit,
30{
31    fn exit(self, context: &mut Ctx) -> impl Future<Output = Never> + Send + '_ {
32        #[derive(Debug, thiserror::Error)]
33        #[error("wrapped dyn-error: {}", _0)]
34        struct AnyErrorWrapped(AnyError);
35
36        async move {
37            match self.map_err(Into::into).map_err(AnyErrorWrapped) {
38                Ok(()) => context.quit_ok().await,
39                Err(reason) => context.quit_err(reason).await,
40            }
41        }
42    }
43}