feat(sdk): Add a way to wait for a sync to be done

master
Damir Jelić 2021-09-08 13:35:21 +02:00
parent 5049e8bfbe
commit f80e4b3f06
2 changed files with 10 additions and 0 deletions

View File

@ -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"

View File

@ -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<event_listener::Event>,
}
#[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);
}
}