Fix bus performance
This commit is contained in:
parent
1bf82e4cc4
commit
9c91d81e89
@ -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 <andrey@aidev.ru>"]
|
||||
repository = "https://github.com/andreytkachenko/messagebus.git"
|
||||
keywords = ["futures", "async", "tokio", "message", "bus"]
|
||||
|
@ -140,7 +140,7 @@ impl BusBuilder {
|
||||
|
||||
pub fn register<T: Send + Sync + 'static>(self, item: T) -> RegisterEntry<SyncEntry, T> {
|
||||
RegisterEntry {
|
||||
item: Untyped::new_rwlock(item),
|
||||
item: Untyped::new_readonly(item),
|
||||
builder: self,
|
||||
receivers: HashMap::new(),
|
||||
_m: Default::default(),
|
||||
|
@ -59,8 +59,7 @@ impl BusInner {
|
||||
|
||||
pub fn try_send<M: Message>(&self, msg: M) -> core::result::Result<(), SendError<M>> {
|
||||
if self.closed.load(Ordering::SeqCst) {
|
||||
println!("Bus closed. Skipping send!");
|
||||
return Ok(());
|
||||
return Err(SendError::Closed(msg));
|
||||
}
|
||||
|
||||
let tid = TypeId::of::<M>();
|
||||
@ -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::<M>());
|
||||
}
|
||||
@ -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::<M>());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user