2021-06-18 21:01:13 +04:00
|
|
|
use messagebus::{receivers, Bus, Handler};
|
2020-12-17 17:35:11 +04:00
|
|
|
|
|
|
|
struct TmpReceiver;
|
|
|
|
|
|
|
|
impl Handler<f32> for TmpReceiver {
|
2021-06-18 21:01:13 +04:00
|
|
|
type Error = anyhow::Error;
|
|
|
|
type Response = ();
|
|
|
|
|
|
|
|
fn handle(&self, msg: f32, _bus: &Bus) -> Result<Self::Response, Self::Error> {
|
2020-12-17 17:35:11 +04:00
|
|
|
println!("---> f32 {}", msg);
|
|
|
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(5));
|
|
|
|
|
|
|
|
println!("done");
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Handler<u16> for TmpReceiver {
|
2021-06-18 21:01:13 +04:00
|
|
|
type Error = anyhow::Error;
|
|
|
|
type Response = ();
|
|
|
|
|
|
|
|
fn handle(&self, msg: u16, _bus: &Bus) -> Result<Self::Response, Self::Error> {
|
2020-12-17 17:35:11 +04:00
|
|
|
println!("---> u16 {}", msg);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Handler<u32> for TmpReceiver {
|
2021-06-18 21:01:13 +04:00
|
|
|
type Error = anyhow::Error;
|
|
|
|
type Response = ();
|
|
|
|
|
|
|
|
fn handle(&self, msg: u32, _bus: &Bus) -> Result<Self::Response, Self::Error> {
|
2020-12-17 17:35:11 +04:00
|
|
|
println!("---> u32 {}", msg);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let (b, poller) = Bus::build()
|
|
|
|
.register(TmpReceiver)
|
2021-06-18 21:01:13 +04:00
|
|
|
.subscribe::<f32, receivers::BufferUnorderedSync<_>, _, _>(8, Default::default())
|
|
|
|
.subscribe::<u16, receivers::BufferUnorderedSync<_>, _, _>(8, Default::default())
|
|
|
|
.subscribe::<u32, receivers::BufferUnorderedSync<_>, _, _>(8, Default::default())
|
2020-12-17 17:35:11 +04:00
|
|
|
.done()
|
|
|
|
.build();
|
|
|
|
|
|
|
|
b.send(32f32).await.unwrap();
|
|
|
|
b.send(11u16).await.unwrap();
|
|
|
|
b.send(32u32).await.unwrap();
|
|
|
|
|
2021-06-18 21:01:13 +04:00
|
|
|
println!("flush");
|
|
|
|
b.flush().await;
|
|
|
|
|
|
|
|
println!("close");
|
|
|
|
b.close().await;
|
|
|
|
|
2021-06-23 16:20:10 +04:00
|
|
|
println!("closed");
|
|
|
|
|
2021-06-18 21:01:13 +04:00
|
|
|
poller.await;
|
|
|
|
println!("[done]");
|
2020-12-17 17:35:11 +04:00
|
|
|
}
|