diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-18 12:42:25 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-18 12:42:25 +0200 |
commit | cfc02ba3685c481ebb71ffeddc970998af987de9 (patch) | |
tree | 04a2631f295b9a0a0e5764655dbab22fb61b8c6a /src/bayou.rs | |
parent | 7a3ce9f81963cc374271272bfe4e0e204e9b7012 (diff) | |
download | aerogramme-cfc02ba3685c481ebb71ffeddc970998af987de9.tar.gz aerogramme-cfc02ba3685c481ebb71ffeddc970998af987de9.zip |
more stuff
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)] |