Skip to content

Commit

Permalink
do not handle broadcast send Ok result with 0 listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed May 21, 2024
1 parent 4d0a538 commit cb658ca
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions crates/tokio-util/src/event_listeners.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use tokio::sync::broadcast::{self, Sender};
use tokio_stream::wrappers::BroadcastStream;
use tracing::{error, warn};
use tracing::error;

const DEFAULT_SIZE_BROADCAST_CHANNEL: usize = 1000;

Expand All @@ -26,14 +26,9 @@ impl<T: Clone + Send + Sync + 'static> EventListeners<T> {

/// Broadcasts an event to all listeners.
pub fn notify(&self, event: T) {
match self.sender.send(event) {
Ok(listener_count) => {
if listener_count == 0 {
warn!("notification of network event with 0 listeners");
}
}
Err(_) => error!("channel closed"),
};
if self.sender.send(event).is_err() {
error!("channel closed");
}
}

/// Adds a new event listener and returns the associated receiver.
Expand Down

0 comments on commit cb658ca

Please sign in to comment.