Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Aug 3, 2024
1 parent c39661d commit 3e9b11e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/asyncv/attribute/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 5 additions & 0 deletions src/asyncv/attribute/message/boolean/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -34,6 +35,10 @@ impl AttributeBoolean {
}
}

pub fn with_boolean_message_handler(handler: Arc<Mutex<dyn OnBooleanMessage>>) {
// let Box<dyn
}

// pub async fn on_change_handler(&self, handler: Box<dyn OnChangeHandler>) {
// self.inner.lock().await.on_change_handler(handler);
// }
Expand Down
15 changes: 13 additions & 2 deletions src/examples/test_async.rs
Original file line number Diff line number Diff line change
@@ -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<Mutex<TestBehaviour>> {
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) {}
}

Expand Down

0 comments on commit 3e9b11e

Please sign in to comment.