serviceless 0.5.8

An simple actor model in rust, like actix
Documentation
use crate::{
    runtime::{OneshotSender, Runtime},
    Error, Message,
};

pub struct RuntimedReplyHandle<M, R>
where
    M: Message + Send + 'static,
    M::Result: Send,
    R: Runtime,
{
    sender: Option<R::OneshotSender<M::Result>>,
}

impl<M, R> RuntimedReplyHandle<M, R>
where
    M: Message + Send + 'static,
    M::Result: Send,
    R: Runtime,
{
    pub(crate) fn new(sender: Option<R::OneshotSender<M::Result>>) -> Self {
        Self { sender }
    }

    pub fn send(self, value: M::Result) -> std::result::Result<(), Error> {
        if let Some(sender) = self.sender {
            sender.send(value).map_err(|_| Error::ServiceStoped)
        } else {
            Ok(())
        }
    }

    pub fn is_closed(&self) -> bool {
        if let Some(sender) = &self.sender {
            sender.is_closed()
        } else {
            false
        }
    }
}