Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4edb49b authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Use tokio::spawn instead of choosing the runtime explicitly

tokio::spawn chooses the correct current runtime the caller is in the
context in, so there is no need to explicitly specific topstack runtime.
This makes the code less dependent on a particular runtime.

Bug: 188718349
Tag: #floss
Test: manual - Build floss on Linux

Change-Id: Ided764f4f737bd98ae85b6c06ebe1539e03b3b2c
parent e5014832
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

        // The `resource` is a task that should be spawned onto a tokio compatible
        // reactor ASAP. If the resource ever finishes, we lost connection to D-Bus.
        topstack::get_runtime().spawn(async {
        tokio::spawn(async {
            let err = resource.await;
            panic!("Lost connection to D-Bus: {}", err);
        });
@@ -106,7 +106,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
        cr.lock().unwrap().set_async_support(Some((
            conn.clone(),
            Box::new(|x| {
                topstack::get_runtime().spawn(x);
                tokio::spawn(x);
            }),
        )));
        let cr_clone = cr.clone();
+1 −1
Original line number Diff line number Diff line
@@ -402,7 +402,7 @@ pub fn dbus_proxy_obj(attr: TokenStream, item: TokenStream) -> TokenStream {
                    let remote__ = self.remote.clone();
                    let objpath__ = self.objpath.clone();
                    let conn__ = self.conn.clone();
                    bt_topshim::topstack::get_runtime().spawn(async move {
                    tokio::spawn(async move {
                        let proxy = dbus::nonblock::Proxy::new(
                            remote__,
                            objpath__,
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn Error>> {

        // The `resource` is a task that should be spawned onto a tokio compatible
        // reactor ASAP. If the resource ever finishes, we lost connection to D-Bus.
        topstack::get_runtime().spawn(async {
        tokio::spawn(async {
            let err = resource.await;
            panic!("Lost connection to D-Bus: {}", err);
        });
@@ -63,12 +63,12 @@ fn main() -> Result<(), Box<dyn Error>> {
        cr.set_async_support(Some((
            conn.clone(),
            Box::new(|x| {
                topstack::get_runtime().spawn(x);
                tokio::spawn(x);
            }),
        )));

        // Run the stack main dispatch loop.
        topstack::get_runtime().spawn(Stack::dispatch(rx, bluetooth.clone()));
        tokio::spawn(Stack::dispatch(rx, bluetooth.clone()));

        // Set up the disconnect watcher to monitor client disconnects.
        let disconnect_watcher = Arc::new(Mutex::new(DisconnectWatcher::new()));
+1 −1
Original line number Diff line number Diff line
@@ -296,7 +296,7 @@ impl IBluetooth for Bluetooth {

        callback.register_disconnect(Box::new(move || {
            let tx = tx.clone();
            topstack::get_runtime().spawn(async move {
            tokio::spawn(async move {
                let _result = tx.send(Message::BluetoothCallbackDisconnected(id)).await;
            });
        }));