Skip to content

Commit

Permalink
⬆️ zb: Update event-listener to 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Oct 17, 2023
1 parent 1856c0f commit 8498065
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions book/src/blocking.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ fn main() -> Result<(), Box<dyn Error>> {
name: "GreeterName".to_string(),
done: event_listener::Event::new(),
};
let done_listener = greeter.done.listen();
let mut done_listener = greeter.done.listen();
let _handle = connection::Builder::session()?
.name("org.zbus.MyGreeter")?
.serve_at("/org/zbus/MyGreeter", greeter)?
.build()?;
done_listener.wait();
done_listener.as_mut().wait();
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions book/src/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ async fn main() -> Result<()> {
name: "GreeterName".to_string(),
done: event_listener::Event::new(),
};
let done_listener = greeter.done.listen();
let mut done_listener = greeter.done.listen();
let _connection = Builder::session()?
.name("org.zbus.MyGreeter")?
.serve_at("/org/zbus/MyGreeter", greeter)?
.build()
.await?;
done_listener.wait();
done_listener.as_mut().wait();
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion zbus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ hex = "0.4.3"
ordered-stream = "0.2"
rand = "0.8.5"
sha1 = { version = "0.10.5", features = ["std"] }
event-listener = "2.5.3"
event-listener = "3.0.0"
static_assertions = "1.1.0"
async-trait = "0.1.58"
async-fs = { version = "1.6.0", optional = true }
Expand Down
16 changes: 12 additions & 4 deletions zbus/src/blocking/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ mod tests {
});

let c = Builder::unix_stream(p1).p2p().build().unwrap();
let listener = c.monitor_activity();

let mut listener = Box::pin(c.monitor_activity());
listener.as_mut().listen();

let mut s = MessageIterator::from(&c);
tx.send(()).unwrap();
let m = s.next().unwrap().unwrap();
Expand All @@ -326,11 +329,16 @@ mod tests {
assert_eq!(val, "yay");

// there was some activity
listener.wait();
listener.as_mut().wait();
// eventually, nothing happens and it will timeout
loop {
let listener = c.monitor_activity();
if !listener.wait_timeout(std::time::Duration::from_millis(10)) {
let mut listener = Box::pin(c.monitor_activity());
listener.as_mut().listen();
if listener
.as_mut()
.wait_timeout(std::time::Duration::from_millis(10))
.is_none()
{
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions zbus/src/blocking/object_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ where
/// let connection = Connection::session()?;
///
/// let quit_event = Event::new();
/// let quit_listener = quit_event.listen();
/// let mut quit_listener = quit_event.listen();
/// let interface = Example::new(quit_event);
/// connection
/// .object_server()
/// .at("/org/zbus/path", interface)?;
///
/// quit_listener.wait();
/// quit_listener.as_mut().wait();
/// # Ok::<_, Box<dyn Error + Send + Sync>>(())
/// ```
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion zbus/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ impl Connection {
///
/// This function is meant for the caller to implement idle or timeout on inactivity.
pub fn monitor_activity(&self) -> EventListener {
self.inner.activity_event.listen()
EventListener::new(&self.inner.activity_event)
}

/// Returns the peer credentials.
Expand Down
2 changes: 1 addition & 1 deletion zbus/src/object_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ impl<R> ResponseDispatchNotifier<R> {
/// Create a new `NotifyResponse`.
pub fn new(response: R) -> (Self, EventListener) {
let event = Event::new();
let listener = event.listen();
let listener = EventListener::new(&event);
(
Self {
response,
Expand Down
2 changes: 1 addition & 1 deletion zbus/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ where
pub struct PropertyStream<'a, T> {
name: &'a str,
proxy: Proxy<'a>,
changed_listener: EventListener,
changed_listener: Pin<Box<EventListener>>,
phantom: std::marker::PhantomData<T>,
}

Expand Down
4 changes: 3 additions & 1 deletion zbus/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ impl MyIfaceImpl {
) -> zbus::fdo::Result<ResponseDispatchNotifier<String>> {
debug!("`TestResponseNotify` called.");
let (response, listener) = ResponseDispatchNotifier::new(String::from("Meaning of life"));
let mut listener = Box::pin(listener);
listener.as_mut().listen();
let ctxt = ctxt.to_owned();
conn.executor()
.spawn(
Expand Down Expand Up @@ -693,6 +695,7 @@ fn iface_and_proxy_unix_p2p() {
#[instrument]
async fn iface_and_proxy_(p2p: bool) {
let event = event_listener::Event::new();
let listen = event.listen();
let guid = zbus::Guid::generate();

let (service_conn_builder, client_conn_builder) = if p2p {
Expand Down Expand Up @@ -770,7 +773,6 @@ async fn iface_and_proxy_(p2p: bool) {
debug!("Client connection created: {:?}", client_conn);
debug!("Service connection created: {:?}", service_conn);

let listen = event.listen();
let child = client_conn
.executor()
.spawn(my_iface_test(client_conn.clone(), event), "client_task");
Expand Down

0 comments on commit 8498065

Please sign in to comment.