diff options
Diffstat (limited to 'src/bayou.rs')
-rw-r--r-- | src/bayou.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/bayou.rs b/src/bayou.rs index 8fc711e..1ea8395 100644 --- a/src/bayou.rs +++ b/src/bayou.rs @@ -62,18 +62,29 @@ impl<S: BayouState> Bayou<S> { }) } + /// Re-reads the state from persistent storage backend pub async fn sync(&mut self) -> Result<()> { // 1. List checkpoints - // 2. Load last checkpoint + // 2. Load last checkpoint if different from currently used one // 3. List all operations starting from checkpoint // 4. Check that first operation has same timestamp as checkpoint (if not zero) // 5. Apply all operations in order unimplemented!() } - pub fn state(&self) -> &S { + /// Applies a new operation on the state. Once this function returns, + /// the option has been safely persisted to storage backend + pub async fn push(&mut self, op: S::Op) -> Result<()> { unimplemented!() } + + pub fn state(&self) -> &S { + if let Some(last) = self.history.last() { + last.2.as_ref().unwrap() + } else { + &self.checkpoint.1 + } + } } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] |