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