Skip to content

Commit d21c314

Browse files
committed
change(ffi): use a OnceLock to guard against multiple settings of the ClientDelegate
1 parent fb41376 commit d21c314

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

bindings/matrix-sdk-ffi/src/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl From<matrix_sdk::TransmissionProgress> for TransmissionProgress {
220220
#[derive(uniffi::Object)]
221221
pub struct Client {
222222
pub(crate) inner: AsyncRuntimeDropped<MatrixClient>,
223-
delegate: RwLock<Option<Arc<dyn ClientDelegate>>>,
223+
delegate: OnceLock<Arc<dyn ClientDelegate>>,
224224
utd_hook: OnceLock<Arc<UtdHookManager>>,
225225
session_verification_controller:
226226
Arc<tokio::sync::RwLock<Option<SessionVerificationController>>>,
@@ -265,7 +265,7 @@ impl Client {
265265

266266
let client = Client {
267267
inner: AsyncRuntimeDropped::new(sdk_client.clone()),
268-
delegate: RwLock::new(None),
268+
delegate: OnceLock::new(),
269269
utd_hook: OnceLock::new(),
270270
session_verification_controller,
271271
};
@@ -774,7 +774,7 @@ impl Client {
774774
}
775775
});
776776

777-
*self.delegate.write().unwrap() = Some(Arc::from(delegate));
777+
self.delegate.get_or_init(|| Arc::from(delegate));
778778
Arc::new(TaskHandle::new(session_change_task))
779779
})
780780
}
@@ -1486,7 +1486,7 @@ impl From<&search_users::v3::User> for UserProfile {
14861486

14871487
impl Client {
14881488
fn process_session_change(&self, session_change: SessionChange) {
1489-
if let Some(delegate) = self.delegate.read().unwrap().clone() {
1489+
if let Some(delegate) = self.delegate.get().cloned() {
14901490
debug!("Applying session change: {session_change:?}");
14911491
get_runtime_handle().spawn_blocking(move || match session_change {
14921492
SessionChange::UnknownToken { soft_logout } => {

0 commit comments

Comments
 (0)