use crate::concurrency;
use crate::MessagingErr;
pub mod output;
pub use output::*;
#[derive(Debug)]
pub struct RpcReplyPort<TMsg> {
port: concurrency::OneshotSender<TMsg>,
timeout: Option<concurrency::Duration>,
}
impl<TMsg> RpcReplyPort<TMsg> {
pub fn get_timeout(&self) -> Option<concurrency::Duration> {
self.timeout
}
pub fn send(self, msg: TMsg) -> Result<(), MessagingErr<TMsg>> {
self.port.send(msg).map_err(|t| MessagingErr::SendErr(t))
}
pub fn is_closed(&self) -> bool {
self.port.is_closed()
}
}
impl<TMsg> From<concurrency::OneshotSender<TMsg>> for RpcReplyPort<TMsg> {
fn from(value: concurrency::OneshotSender<TMsg>) -> Self {
Self {
port: value,
timeout: None,
}
}
}
impl<TMsg> From<(concurrency::OneshotSender<TMsg>, concurrency::Duration)> for RpcReplyPort<TMsg> {
fn from((value, timeout): (concurrency::OneshotSender<TMsg>, concurrency::Duration)) -> Self {
Self {
port: value,
timeout: Some(timeout),
}
}
}