Skip to content

Commit ed4a3fd

Browse files
warusadurabilelmoussaoui
authored andcommitted
server: Wrap Service.connection inside an Arc
And drop changes introduced in da99ffe Fixes error: called `Option::unwrap()` on a `None` value when accessing service.collection field.
1 parent ab3b19c commit ed4a3fd

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

server/src/service.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Service {
3737
// Properties
3838
collections: Arc<Mutex<Vec<Collection>>>,
3939
// Other attributes
40-
connection: OnceLock<zbus::Connection>,
40+
connection: Arc<OnceLock<zbus::Connection>>,
4141
// sessions mapped to their corresponding object path on the bus
4242
sessions: Arc<Mutex<HashMap<OwnedObjectPath, Session>>>,
4343
session_index: Arc<RwLock<u32>>,
@@ -305,21 +305,19 @@ impl Service {
305305
prompt_index: Default::default(),
306306
};
307307

308-
let connection_builder = zbus::connection::Builder::session()?
308+
let connection = zbus::connection::Builder::session()?
309309
.allow_name_replacements(true)
310310
.replace_existing_names(request_replacement)
311311
.name(oo7::dbus::api::Service::DESTINATION.as_deref().unwrap())?
312312
.serve_at(
313313
oo7::dbus::api::Service::PATH.as_deref().unwrap(),
314314
service.clone(),
315-
)?;
316-
317-
service
318-
.connection
319-
.set(connection_builder.build().await?)
320-
.unwrap();
315+
)?
316+
.build()
317+
.await?;
318+
service.connection.set(connection.clone()).unwrap();
321319

322-
let object_server = service.object_server();
320+
let object_server = connection.object_server();
323321
let mut collections = service.collections.lock().await;
324322

325323
if let Some(secret) = secret {

0 commit comments

Comments
 (0)