rsiot/components/shared_tasks/
msgbus_to_mpsc.rs1use tokio::sync::mpsc::Sender;
4
5use crate::{
6 executor::MsgBusInput,
7 message::{Message, MsgDataBound},
8};
9
10pub struct MsgBusToMpsc<TMsg>
12where
13 TMsg: MsgDataBound,
14{
15 pub input: MsgBusInput<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.input.recv().await {
29 self.output
30 .send(msg)
31 .await
32 .map_err(|_| Error::TokioSyncMpscSend)?;
33 }
34 Ok(())
35 }
36}
37
38#[allow(missing_docs)]
39#[derive(thiserror::Error, Debug)]
40pub enum Error {
41 #[error("MsgBusToMpsc | TokioSyncMpscSend")]
42 TokioSyncMpscSend,
43}