Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(store): cancel auto save on save #1859

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Cancel auto save on save
Legend-Master committed Oct 2, 2024
commit 93e47f0c411d434afd68a1a921ed598161457a35
14 changes: 4 additions & 10 deletions plugins/store/src/store.rs
Original file line number Diff line number Diff line change
@@ -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)
}

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