diff --git a/src/asyncv/attribute/message.rs b/src/asyncv/attribute/message.rs index 6afeaa5..1e52a89 100644 --- a/src/asyncv/attribute/message.rs +++ b/src/asyncv/attribute/message.rs @@ -22,6 +22,6 @@ pub trait OnMessageHandler: Send + Sync { } #[async_trait] -pub trait OnMessageBoolean: Send + Sync { +pub trait OnBooleanMessage: Send + Sync { async fn on_message_boolean(&mut self, id: AttributeId, data: bool); } diff --git a/src/asyncv/attribute/message/boolean/attribute.rs b/src/asyncv/attribute/message/boolean/attribute.rs index 3cac60a..c92b225 100644 --- a/src/asyncv/attribute/message/boolean/attribute.rs +++ b/src/asyncv/attribute/message/boolean/attribute.rs @@ -5,6 +5,7 @@ use std::future::Future; use std::sync::Arc; use tokio::sync::Mutex; +use crate::asyncv::attribute::message::OnBooleanMessage; use crate::AttributeError; use async_trait::async_trait; @@ -34,6 +35,10 @@ impl AttributeBoolean { } } + pub fn with_boolean_message_handler(handler: Arc>) { + // let Box) { // self.inner.lock().await.on_change_handler(handler); // } diff --git a/src/examples/test_async.rs b/src/examples/test_async.rs index 01d0f82..2eb0ae4 100644 --- a/src/examples/test_async.rs +++ b/src/examples/test_async.rs @@ -1,15 +1,26 @@ +use std::sync::Arc; + use async_trait::async_trait; + use panduza::asyncv::attribute::message::AttributeId; -use panduza::asyncv::attribute::message::OnMessageBoolean; +use panduza::asyncv::attribute::message::OnBooleanMessage; use panduza::asyncv::Reactor; use panduza::ReactorSettings; use tokio::time::sleep; use tokio::time::Duration; +use tokio::sync::Mutex; + struct TestBehaviour {} +impl TestBehaviour { + pub fn to_arc_mutex(self) -> Arc> { + Arc::new(Mutex::new(self)) + } +} + #[async_trait] -impl OnMessageBoolean for TestBehaviour { +impl OnBooleanMessage for TestBehaviour { async fn on_message_boolean(&mut self, id: AttributeId, data: bool) {} }