Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
b63a3f9f20 |
@ -1,4 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
#![feature(associated_type_defaults, generic_associated_types, type_alias_impl_trait)]
|
||||||
|
|
||||||
|
use futures::Future;
|
||||||
use messagebus::{derive::Message, error, AsyncHandler, Bus, Handler, Message, TypeTagged};
|
use messagebus::{derive::Message, error, AsyncHandler, Bus, Handler, Message, TypeTagged};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
@ -37,117 +39,166 @@ struct MsgI32(i32);
|
|||||||
#[message(clone)]
|
#[message(clone)]
|
||||||
struct MsgI16(i16);
|
struct MsgI16(i16);
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AsyncHandler<MsgF32> for TmpReceiver {
|
impl AsyncHandler<MsgF32> for TmpReceiver {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
|
|
||||||
async fn handle(&self, msg: MsgF32, bus: &Bus) -> Result<Self::Response, Self::Error> {
|
type AsyncHandleFuture<'a> = impl Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
|
type AsyncSyncFuture<'a> = impl Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
|
|
||||||
|
fn handle(&self, msg: MsgF32, bus: &Bus) -> Self::AsyncHandleFuture<'_> {
|
||||||
|
let bus = bus.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
bus.send(MsgU16(1)).await?;
|
bus.send(MsgU16(1)).await?;
|
||||||
|
|
||||||
println!("TmpReceiver ---> {:?} {}", msg, msg.type_tag());
|
println!("TmpReceiver ---> {:?} {}", msg, msg.type_tag());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver f32: sync");
|
println!("TmpReceiver f32: sync");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AsyncHandler<MsgU16> for TmpReceiver {
|
impl AsyncHandler<MsgU16> for TmpReceiver {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
|
|
||||||
async fn handle(&self, msg: MsgU16, bus: &Bus) -> Result<Self::Response, Self::Error> {
|
type AsyncHandleFuture<'a> = impl Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
|
type AsyncSyncFuture<'a> = impl Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
|
|
||||||
|
fn handle(&self, msg: MsgU16, bus: &Bus) -> Self::AsyncHandleFuture<'_> {
|
||||||
|
let bus = bus.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
bus.send(MsgU32(2)).await?;
|
bus.send(MsgU32(2)).await?;
|
||||||
println!("TmpReceiver ---> {:?}", msg);
|
println!("TmpReceiver ---> {:?}", msg);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver u16: sync");
|
println!("TmpReceiver u16: sync");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AsyncHandler<MsgU32> for TmpReceiver {
|
impl AsyncHandler<MsgU32> for TmpReceiver {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
|
|
||||||
async fn handle(&self, msg: MsgU32, bus: &Bus) -> Result<Self::Response, Self::Error> {
|
type AsyncHandleFuture<'a> = impl Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
|
type AsyncSyncFuture<'a> = impl Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
|
|
||||||
|
fn handle(&self, msg: MsgU32, bus: &Bus) -> Self::AsyncHandleFuture<'_> {
|
||||||
|
let bus = bus.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
bus.send(MsgI32(3)).await?;
|
bus.send(MsgI32(3)).await?;
|
||||||
println!("TmpReceiver ---> {:?}", msg);
|
println!("TmpReceiver ---> {:?}", msg);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
}
|
||||||
|
|
||||||
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver u32: sync");
|
println!("TmpReceiver u32: sync");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AsyncHandler<MsgI32> for TmpReceiver {
|
impl AsyncHandler<MsgI32> for TmpReceiver {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
|
|
||||||
async fn handle(&self, msg: MsgI32, bus: &Bus) -> Result<Self::Response, Self::Error> {
|
type AsyncHandleFuture<'a> = impl Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
|
type AsyncSyncFuture<'a> = impl Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
|
|
||||||
|
fn handle(&self, msg: MsgI32, bus: &Bus) -> Self::AsyncHandleFuture<'_> {
|
||||||
|
let bus = bus.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
bus.send(MsgI16(4)).await?;
|
bus.send(MsgI16(4)).await?;
|
||||||
println!("TmpReceiver ---> {:?}", msg);
|
println!("TmpReceiver ---> {:?}", msg);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver i32: sync");
|
println!("TmpReceiver i32: sync");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AsyncHandler<MsgI16> for TmpReceiver {
|
impl AsyncHandler<MsgI16> for TmpReceiver {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
|
|
||||||
async fn handle(&self, msg: MsgI16, _bus: &Bus) -> Result<Self::Response, Self::Error> {
|
type AsyncHandleFuture<'a> = impl Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
|
type AsyncSyncFuture<'a> = impl Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
|
|
||||||
|
fn handle(&self, msg: MsgI16, _bus: &Bus) -> Self::AsyncHandleFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver ---> {:?}", msg);
|
println!("TmpReceiver ---> {:?}", msg);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
}
|
||||||
|
|
||||||
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver i16: sync");
|
println!("TmpReceiver i16: sync");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl AsyncHandler<MsgI32> for TmpReceiver2 {
|
impl AsyncHandler<MsgI32> for TmpReceiver2 {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Response = ();
|
type Response = ();
|
||||||
|
|
||||||
async fn handle(&self, msg: MsgI32, bus: &Bus) -> Result<Self::Response, Self::Error> {
|
type AsyncHandleFuture<'a> = impl Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
|
type AsyncSyncFuture<'a> = impl Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
|
|
||||||
|
fn handle(&self, msg: MsgI32, bus: &Bus) -> Self::AsyncHandleFuture<'_> {
|
||||||
|
let bus = bus.clone();
|
||||||
|
|
||||||
|
async move {
|
||||||
println!("TmpReceiver2: ---> {:?}", msg);
|
println!("TmpReceiver2: ---> {:?}", msg);
|
||||||
|
|
||||||
bus.send(MsgI16(5)).await?;
|
bus.send(MsgI16(5)).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
}
|
||||||
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_> {
|
||||||
|
async move {
|
||||||
println!("TmpReceiver2: i32: sync");
|
println!("TmpReceiver2: i32: sync");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Handler<MsgI16> for TmpReceiver2 {
|
impl Handler<MsgI16> for TmpReceiver2 {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
@ -2,6 +2,7 @@ use core::iter::FromIterator;
|
|||||||
|
|
||||||
use crate::{error::StdSyncSendError, Bus, Message};
|
use crate::{error::StdSyncSendError, Bus, Message};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use futures::Future;
|
||||||
|
|
||||||
pub trait Handler<M: Message>: Send + Sync {
|
pub trait Handler<M: Message>: Send + Sync {
|
||||||
type Error: StdSyncSendError;
|
type Error: StdSyncSendError;
|
||||||
@ -13,15 +14,15 @@ pub trait Handler<M: Message>: Send + Sync {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
pub trait AsyncHandler<M: Message>: Send + Sync {
|
pub trait AsyncHandler<M: Message>: Send + Sync {
|
||||||
type Error: StdSyncSendError;
|
type Error: StdSyncSendError;
|
||||||
type Response: Message;
|
type Response: Message;
|
||||||
|
|
||||||
async fn handle(&self, msg: M, bus: &Bus) -> Result<Self::Response, Self::Error>;
|
type AsyncHandleFuture<'a>: Future<Output = Result<Self::Response, Self::Error>> + Send + Sync + 'a;
|
||||||
async fn sync(&self, _bus: &Bus) -> Result<(), Self::Error> {
|
type AsyncSyncFuture<'a>: Future<Output = Result<(), Self::Error>> + Send + Sync + 'a;
|
||||||
Ok(())
|
|
||||||
}
|
fn handle(&self, msg: M, bus: &Bus) -> Self::AsyncHandleFuture<'_>;
|
||||||
|
fn sync(&self, _bus: &Bus) -> Self::AsyncSyncFuture<'_>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SynchronizedHandler<M: Message>: Send {
|
pub trait SynchronizedHandler<M: Message>: Send {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![feature(associated_type_defaults, generic_associated_types, type_alias_impl_trait)]
|
||||||
|
|
||||||
mod builder;
|
mod builder;
|
||||||
mod envelop;
|
mod envelop;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
Loading…
Reference in New Issue
Block a user