Skip to content

Commit

Permalink
Revert "🚸 zb: Connection::monitor_activity now returns Activity type"
Browse files Browse the repository at this point in the history
This reverts commit 366e24a.

New event-listener with breaking API (5.0.0) is already out and we
already ported to that so we don't need this abstraction anymore.
  • Loading branch information
zeenix committed Feb 7, 2024
1 parent 75938fa commit 381c562
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 69 deletions.
56 changes: 10 additions & 46 deletions zbus/src/blocking/connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
//! Blocking connection API.
use enumflags2::BitFlags;
use event_listener::EventListener;
use static_assertions::assert_impl_all;
use std::{
io,
ops::Deref,
time::{Duration, Instant},
};
use event_listener::Listener;
use std::{io, ops::Deref};
use zbus_names::{BusName, ErrorName, InterfaceName, MemberName, OwnedUniqueName, WellKnownName};
use zvariant::ObjectPath;

Expand Down Expand Up @@ -242,13 +238,11 @@ impl Connection {
self.inner
}

/// Returns an [`Activity`] instance to wait for various connection activity.
/// Returns a listener, notified on various connection activity.
///
/// This function is meant for the caller to implement idle or timeout on inactivity.
pub fn monitor_activity(&self) -> Activity {
Activity {
inner: self.inner.monitor_activity(),
}
pub fn monitor_activity(&self) -> EventListener {
self.inner.monitor_activity()
}

/// Returns the peer credentials.
Expand Down Expand Up @@ -277,40 +271,6 @@ impl From<crate::Connection> for Connection {
}
}

/// Allows you to wait for activity on the connection.
///
/// Use [`Connection::monitor_activity`] to get an instance of this type.
#[derive(Debug)]
pub struct Activity {
inner: crate::connection::Activity,
}

assert_impl_all!(Activity: Send, Sync, Unpin);

impl Activity {
/// Wait indefinitely for the activity.
pub fn wait(self) {
self.inner.listener.wait()
}

/// Wait for the activity for the given amount of time.
///
/// Returns `true` if an activity occurred, `false` if it timedout.
pub fn wait_timeout(self, timeout: Duration) -> bool {
self.inner.listener.wait_timeout(timeout).is_some()
}

/// Wait for the activity until the given time.
///
/// Returns `true` if an activity occurred, `false` if the deadline was reached.
pub fn wait_deadline(self, deadline: Instant) -> bool {
self.inner
.listener
.wait_deadline(deadline)
.is_some()
}
}

#[cfg(all(test, unix))]
mod tests {
use ntest::timeout;
Expand All @@ -322,6 +282,7 @@ mod tests {
use tokio::net::UnixStream;
#[cfg(all(windows, not(feature = "tokio")))]
use uds_windows::UnixStream;
use event_listener::Listener;

use crate::{
blocking::{connection::Builder, MessageIterator},
Expand Down Expand Up @@ -373,7 +334,10 @@ mod tests {
// eventually, nothing happens and it will timeout
loop {
let listener = c.monitor_activity();
if !listener.wait_timeout(std::time::Duration::from_millis(10)) {
if listener
.wait_timeout(std::time::Duration::from_millis(10))
.is_none()
{
break;
}
}
Expand Down
26 changes: 3 additions & 23 deletions zbus/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1211,13 +1211,11 @@ impl Connection {
Builder::system()?.build().await
}

/// Returns an [`Activity`] instance to wait for various connection activity.
/// Returns a listener, notified on various connection activity.
///
/// This function is meant for the caller to implement idle or timeout on inactivity.
pub fn monitor_activity(&self) -> Activity {
Activity {
listener: self.inner.activity_event.listen(),
}
pub fn monitor_activity(&self) -> EventListener {
self.inner.activity_event.listen()
}

/// Returns the peer credentials.
Expand Down Expand Up @@ -1307,24 +1305,6 @@ enum NameStatus {
Queued(#[allow(unused)] Task<()>),
}

/// A future that resolves when there is activity on the connection.
///
/// Use [`Connection::monitor_activity`] to get an instance of this type.
#[derive(Debug)]
pub struct Activity {
pub(crate) listener: EventListener,
}

assert_impl_all!(Activity: Send, Sync, Unpin);

impl Future for Activity {
type Output = ();

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Future::poll(Pin::new(&mut self.as_mut().listener), cx)
}
}

#[cfg(test)]
mod tests {
use futures_util::stream::TryStreamExt;
Expand Down

0 comments on commit 381c562

Please sign in to comment.