Skip to main content

coven/
handle_sync_status.rs

1//! The sync state an app shows, read from coven's own rows (§19.1, E5).
2use crate::*;
3
4impl CovenHandle {
5    /// The sync state and when sync last finished, computed from
6    /// `coven_sync_status`, `coven_retry_effect`, the send queue, the upload
7    /// queue, the files moving and the pending records in one committed
8    /// snapshot (§19.1).
9    pub async fn sync_status(&self) -> CovenResult<SyncStatus> {
10        coven_sync::sync_status(&self.database).await.map_err(CovenError::from)
11    }
12    /// The same pre-built query, live (E4): its first value is the current
13    /// state.
14    pub fn subscribe_sync_status(&self) -> LiveQuery<SyncStatus, CovenError> {
15        self.database.subscribe_sync_facts(|facts| {
16            coven_sync::SyncStatus::computed(facts).map_err(CovenError::from)
17        })
18    }
19    /// Follow the sync state with `subscribe_sync_status`, as an app does (E5).
20    #[cfg(any(test, feature = "test-utils"))]
21    pub fn test_sync_status(&self) -> coven_database::test_utils::Followed<SyncStatus, CovenError> {
22        coven_database::test_utils::Followed::new(self.subscribe_sync_status())
23    }
24    /// Follow `coven_sync_status.last_pass` with a live query, as an app's
25    /// SQL does (E4): `None` until a pass ends on this device.
26    #[cfg(any(test, feature = "test-utils"))]
27    pub fn test_last_pass(
28        &self,
29    ) -> coven_database::test_utils::Followed<Option<LastPass>, DbError> {
30        LastPass::follow(&self.database)
31    }
32}
33
34#[cfg(test)]
35#[path = "handle_sync_status_tests.rs"]
36mod tests;