rsiot/components/shared_tasks/
change_mpsc_msg.rsuse tokio::sync::mpsc::{Receiver, Sender};
pub struct ChangeMpscMsg<TInput, TOutput> {
pub input: Receiver<TInput>,
pub output: Sender<TOutput>,
pub fn_change: fn(TInput) -> TOutput,
}
impl<TInput, TOutput> ChangeMpscMsg<TInput, TOutput> {
pub async fn spawn(mut self) -> Result<(), Error> {
while let Some(input_msg) = self.input.recv().await {
let output_msg = (self.fn_change)(input_msg);
self.output
.send(output_msg)
.await
.map_err(|e| Error::TokioSyncMpsc(e.to_string()))?;
}
Ok(())
}
}
#[allow(missing_docs)]
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("{0}")]
TokioSyncMpsc(String),
}