Blocking API

While zbus API being primarily asynchronous (since 2.0) is a great thing, it could easily feel daunting for simple use cases. Not to worry! In the spirit of “ease” being a primary goal of zbus, it provides blocking wrapper types, under the blocking module.

Note: Use of the blocking API presented in this chapter in an async context will likely result in panics and hangs. This is not a limitation of zbus but rather a well-known general problem in the Rust async/await world. The blocking crate, async-std and tokio crates provide a easy way around this problem.

Establishing a connection

The only difference to that of asynchronous Connection API is that you use blocking::Connection type instead. This type’s API is almost identical to that of Connection, except all its methods are blocking.


Similar to blocking::Connection, you use blocking::Proxy type. Its constructors require blocking::Connection instead of Connection. Moreover, proxy macro generates a blocking::Proxy wrapper for you as well. Let’s convert the last example in the previous chapter, to use the blocking connection and proxy:

fn main() {
use zbus::{blocking::Connection, zvariant::ObjectPath, proxy, Result};

    default_service = "org.freedesktop.GeoClue2",
    interface = "org.freedesktop.GeoClue2.Manager",
    default_path = "/org/freedesktop/GeoClue2/Manager"
trait Manager {
    #[zbus(object = "Client")]
    /// The method normally returns an `ObjectPath`.
    /// With the object attribute, we can make it return a `ClientProxy` directly.
    fn get_client(&self);

    default_service = "org.freedesktop.GeoClue2",
    interface = "org.freedesktop.GeoClue2.Client"
trait Client {
    fn start(&self) -> Result<()>;
    fn stop(&self) -> Result<()>;

    fn set_desktop_id(&mut self, id: &str) -> Result<()>;

    fn location_updated(&self, old: ObjectPath<'_>, new: ObjectPath<'_>) -> Result<()>;

    default_service = "org.freedesktop.GeoClue2",
    interface = "org.freedesktop.GeoClue2.Location"
trait Location {
    fn latitude(&self) -> Result<f64>;
    fn longitude(&self) -> Result<f64>;
let conn = Connection::system().unwrap();
let manager = ManagerProxyBlocking::new(&conn).unwrap();
let mut client = manager.get_client().unwrap();
// Gotta do this, sorry!

let mut location_updated = client.receive_location_updated().unwrap();


// Wait for the signal.
let signal =;
let args = signal.args().unwrap();

let location = LocationProxyBlocking::builder(&conn)
    "Latitude: {}\nLongitude: {}",

As you can see, nothing changed in the proxy usage here and the rest largely remained the same as well. One difference that’s not obvious is that the blocking API for receiving signals, implement std::iter::Iterator trait instead of futures::stream::Stream.

Watching for properties

That’s almost the same as receiving signals:

use zbus::{blocking::Connection, proxy, Result};

    interface = "org.freedesktop.systemd1.Manager",
    default_service = "org.freedesktop.systemd1",
    default_path = "/org/freedesktop/systemd1"
trait SystemdManager {
    fn log_level(&self) -> zbus::Result<String>;

fn main() -> Result<()> {
    let connection = Connection::session()?;

    let proxy = SystemdManagerProxyBlocking::new(&connection)?;
    let v = proxy.receive_log_level_changed().next().unwrap();
    println!("LogLevel changed: {:?}", v.get());



Similarly here, you’d use [blocking::ObjectServer] that is associated with every blocking::Connection instance. While there is no blocking version of Interface, interface allows you to write non-async methods.

Note: Even though you can write non-async methods, these methods are still called from an async context. Therefore, you can not use blocking API in the method implementation directly. See note at the beginning of this chapter for details on why and a possible workaround.

use std::error::Error;
use zbus::{blocking::connection, interface, fdo, SignalContext};

use event_listener::{Event, Listener};

struct Greeter {
    name: String,
    done: Event,

#[interface(name = "org.zbus.MyGreeter1")]
impl Greeter {
    fn say_hello(&self, name: &str) -> String {
        format!("Hello {}!", name)

    // Rude!
    async fn go_away(
        ctxt: SignalContext<'_>,
    ) -> fdo::Result<()> {


    /// A "GreeterName" property.
    fn greeter_name(&self) -> &str {

    /// A setter for the "GreeterName" property.
    /// Additionally, a `greeter_name_changed` method has been generated for you if you need to
    /// notify listeners that "GreeterName" was updated. It will be automatically called when
    /// using this setter.
    fn set_greeter_name(&mut self, name: String) { = name;

    /// A signal; the implementation is provided by the macro.
    async fn greeted_everyone(ctxt: &SignalContext<'_>) -> zbus::Result<()>;

fn main() -> Result<(), Box<dyn Error>> {
    let greeter = Greeter {
        name: "GreeterName".to_string(),
        done: event_listener::Event::new(),
    let done_listener = greeter.done.listen();
    let _handle = connection::Builder::session()?
        .serve_at("/org/zbus/MyGreeter", greeter)?