From 7e5e34420b3facabb81d53ec40435007518da5b5 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:13:20 +0800 Subject: [PATCH] Cancel auto save on save (#1859) --- plugins/store/src/store.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/plugins/store/src/store.rs b/plugins/store/src/store.rs index b18d00277..d610525d3 100644 --- a/plugins/store/src/store.rs +++ b/plugins/store/src/store.rs @@ -437,6 +437,9 @@ impl Store { } pub fn save(&self) -> crate::Result<()> { + if let Some(sender) = self.auto_save_debounce_sender.lock().unwrap().take() { + let _ = sender.send(AutoSaveMessage::Cancel); + } self.store.lock().unwrap().save(self.serialize) } @@ -467,8 +470,8 @@ impl Store { } } _ = sleep(auto_save_delay) => { - let _ = store.lock().unwrap().save(serialize_fn); auto_save_debounce_sender.lock().unwrap().take(); + let _ = store.lock().unwrap().save(serialize_fn); return; } }; @@ -477,12 +480,3 @@ impl Store { Ok(()) } } - -impl Drop for Store { - fn drop(&mut self) { - let auto_save_debounce_sender = self.auto_save_debounce_sender.lock().unwrap(); - if let Some(ref sender) = *auto_save_debounce_sender { - let _ = sender.send(AutoSaveMessage::Cancel); - } - } -}