rsiot/components/shared_tasks/
msgbus_to_mpsc.rs1use tokio::{sync::mpsc::Sender, time::error};
4
5use crate::{
6 executor::CmpInOut,
7 message::{Message, MsgDataBound},
8};
9
10pub struct MsgBusToMpsc<TMsg>
12where
13 TMsg: MsgDataBound,
14{
15 pub msg_bus: CmpInOut<TMsg>,
17
18 pub output: Sender<Message<TMsg>>,
20}
21
22impl<TMsg> MsgBusToMpsc<TMsg>
23where
24 TMsg: MsgDataBound,
25{
26 pub async fn spawn(mut self) -> Result<(), Error> {
28 while let Ok(msg) = self.msg_bus.recv_input().await {
29 self.output
30 .send(msg)
31 .await
32 .map_err(|e| Error::TokioSyncMpsc(e.to_string()))?;
33 }
34 Ok(())
35 }
36}
37
38#[allow(missing_docs)]
39#[derive(thiserror::Error, Debug)]
40pub enum Error {
41 #[error("{0}")]
42 TokioSyncMpsc(String),
43}