Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ impl EventEmitter {
/// [`try_recv`]: Self::try_recv
pub async fn recv(&self) -> Option<Event> {
let mut lock = self.0.lock().await;
lock.recv().await.ok()
loop {
match lock.recv().await {
Err(async_broadcast::RecvError::Overflowed(_)) => {
// Some events have been lost,
// but the channel is not closed.
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth returning a special event telling that some events are lost? I.e. if we don't see such an event in the log, then no events are missing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR adding this event: #5616

}
Err(async_broadcast::RecvError::Closed) => return None,
Ok(event) => return Some(event),
}
}
}

/// Tries to receive an event without blocking.
Expand All @@ -86,8 +96,18 @@ impl EventEmitter {
// to avoid blocking
// in case there is a concurrent call to `recv`.
let mut lock = self.0.try_lock()?;
let event = lock.try_recv()?;
Ok(event)
loop {
match lock.try_recv() {
Err(async_broadcast::TryRecvError::Overflowed(_)) => {
// Some events have been lost,
// but the channel is not closed.
continue;
}
res @ (Err(async_broadcast::TryRecvError::Empty)
| Err(async_broadcast::TryRecvError::Closed)
| Ok(_)) => return Ok(res?),
}
}
}
}

Expand Down