rsiot/components/shared_tasks/
msgbus_to_broadcast.rsuse tokio::{sync::broadcast::Sender, time::error};
use crate::{
executor::CmpInOut,
message::{Message, MsgDataBound, ServiceBound},
};
pub struct MsgBusToBroadcast<TMsg, TService>
where
TMsg: MsgDataBound,
TService: ServiceBound,
{
pub msg_bus: CmpInOut<TMsg, TService>,
pub output: Sender<Message<TMsg>>,
}
impl<TMsg, TService> MsgBusToBroadcast<TMsg, TService>
where
TMsg: MsgDataBound,
TService: ServiceBound,
{
pub async fn spawn(mut self) -> Result<(), Error> {
while let Ok(msg) = self.msg_bus.recv_input().await {
self.output
.send(msg)
.map_err(|e| Error::TokioSyncMpsc(e.to_string()))?;
}
Ok(())
}
}
#[allow(missing_docs)]
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("{0}")]
TokioSyncMpsc(String),
}