Skip to content

Commit

Permalink
Do not mix std::thread with async_std::task
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 11, 2023
1 parent b9989a3 commit 0b2560b
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions rust/agama-dbus-server/src/network/dbus/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module defines a D-Bus service which exposes Agama's network configuration.
use crate::network::NetworkSystem;
use agama_lib::connection_to;
use std::{error::Error, thread};
use std::error::Error;

/// Represents the Agama networking D-Bus service.
///
Expand All @@ -15,24 +15,22 @@ impl NetworkService {
pub async fn start(address: &str) -> Result<(), Box<dyn Error>> {
const SERVICE_NAME: &str = "org.opensuse.Agama.Network1";

let connection = connection_to(address).await?;
let connection = connection_to(address).await.unwrap();
let mut network = NetworkSystem::from_network_manager(connection.clone())
.await
.expect("Could not read network state");

thread::spawn(move || {
async_std::task::block_on(async {
network
.setup()
.await
.expect("Could not set up the D-Bus tree");
connection
.request_name(SERVICE_NAME)
.await
.unwrap_or_else(|_| panic!("Could not request name {SERVICE_NAME}"));
async_std::task::spawn(async move {
network
.setup()
.await
.expect("Could not set up the D-Bus tree");
connection
.request_name(SERVICE_NAME)
.await
.unwrap_or_else(|_| panic!("Could not request name {SERVICE_NAME}"));

network.listen().await;
})
network.listen().await;
});
Ok(())
}
Expand Down

0 comments on commit 0b2560b

Please sign in to comment.