diff --git a/matrix_sdk/Cargo.toml b/matrix_sdk/Cargo.toml index 62e03396..7da4dc56 100644 --- a/matrix_sdk/Cargo.toml +++ b/matrix_sdk/Cargo.toml @@ -33,6 +33,7 @@ docs = ["encryption", "sled_cryptostore", "sled_state_store", "sso_login"] [dependencies] anyhow = { version = "1.0.42", optional = true } dashmap = "4.0.2" +event-listener = "2.5.1" futures = "0.3.15" http = "0.2.4" serde = "1.0.126" diff --git a/matrix_sdk/src/client.rs b/matrix_sdk/src/client.rs index d250e8fe..9ac552fb 100644 --- a/matrix_sdk/src/client.rs +++ b/matrix_sdk/src/client.rs @@ -200,6 +200,12 @@ pub struct Client { /// This is low-level functionality. For an high-level API check the /// `matrix_sdk_appservice` crate. appservice_mode: bool, + /// An event that can be listened on to wait for a successful sync. The + /// event will only be fired if a sync loop is running. Can be used for + /// synchronization, e.g. if we send out a request to create a room, we can + /// wait for the sync to get the data to fetch a room object from the state + /// store. + sync_beat: Arc, } #[cfg(not(tarpaulin_include))] @@ -582,6 +588,7 @@ impl Client { event_handlers: Default::default(), notification_handlers: Default::default(), appservice_mode: config.appservice_mode, + sync_beat: event_listener::Event::new().into(), }) } @@ -2365,6 +2372,8 @@ impl Client { sync_settings.token = Some(self.sync_token().await.expect("No sync token found after initial sync")); + + self.sync_beat.notify(usize::MAX); } }