From 9c91d81e898fe54f1a9c19f04689642f3a505ff2 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Fri, 5 Feb 2021 21:32:19 +0400 Subject: [PATCH] Fix bus performance --- Cargo.toml | 6 +----- src/builder.rs | 2 +- src/lib.rs | 7 +++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 92e91a4..f22583f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,6 @@ [package] name = "messagebus" -<<<<<<< HEAD -version = "0.5.0" -======= -version = "0.5.1" ->>>>>>> db1727b (Local Handlers) +version = "0.5.2" authors = ["Andrey Tkachenko "] repository = "https://github.com/andreytkachenko/messagebus.git" keywords = ["futures", "async", "tokio", "message", "bus"] diff --git a/src/builder.rs b/src/builder.rs index 2470dd8..63e53ec 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -140,7 +140,7 @@ impl BusBuilder { pub fn register(self, item: T) -> RegisterEntry { RegisterEntry { - item: Untyped::new_rwlock(item), + item: Untyped::new_readonly(item), builder: self, receivers: HashMap::new(), _m: Default::default(), diff --git a/src/lib.rs b/src/lib.rs index 20356a1..beddada 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,8 +59,7 @@ impl BusInner { pub fn try_send(&self, msg: M) -> core::result::Result<(), SendError> { if self.closed.load(Ordering::SeqCst) { - println!("Bus closed. Skipping send!"); - return Ok(()); + return Err(SendError::Closed(msg)); } let tid = TypeId::of::(); @@ -71,7 +70,7 @@ impl BusInner { } if let Some((_, r)) = self.receivers.get(range.start) { - r.try_broadcast(msg.clone())?; + r.try_broadcast(msg)?; } else { println!("Unhandled message {:?}", core::any::type_name::()); } @@ -97,7 +96,7 @@ impl BusInner { } if let Some((_, r)) = self.receivers.get(range.start) { - r.broadcast(msg.clone()).await?; + r.broadcast(msg).await?; } else { println!("Unhandled message {:?}", core::any::type_name::()); }