Skip to content

Commit

Permalink
Cancel auto save on save
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Oct 2, 2024
1 parent f12d356 commit 93e47f0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions plugins/store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ impl<R: Runtime> Store<R> {
}

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)
}

Expand Down Expand Up @@ -467,8 +470,8 @@ impl<R: Runtime> Store<R> {
}
}
_ = 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;
}
};
Expand All @@ -477,12 +480,3 @@ impl<R: Runtime> Store<R> {
Ok(())
}
}

impl<R: Runtime> Drop for Store<R> {
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);
}
}
}

0 comments on commit 93e47f0

Please sign in to comment.