From cfc02ba3685c481ebb71ffeddc970998af987de9 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 18 May 2022 12:42:25 +0200 Subject: more stuff --- src/bayou.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/bayou.rs') 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 Bayou { }) } + /// 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)] -- cgit v1.2.3