1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

eframe native: persist app state in background thread

Gives smoother frame rate
This commit is contained in:
Emil Ernerfeldt
2022-04-19 21:26:35 +02:00
parent 1dee439ab1
commit 558891c146
3 changed files with 12 additions and 5 deletions

View File

@@ -59,11 +59,17 @@ impl crate::Storage for FileStorage {
fn flush(&mut self) {
if self.dirty {
// eprintln!("Persisted to {}", self.path.display());
let file = std::fs::File::create(&self.ron_filepath).unwrap();
let config = Default::default();
ron::ser::to_writer_pretty(file, &self.kv, config).unwrap();
self.dirty = false;
let file_path = self.ron_filepath.clone();
let kv = self.kv.clone();
std::thread::spawn(move || {
let file = std::fs::File::create(&file_path).unwrap();
let config = Default::default();
ron::ser::to_writer_pretty(file, &kv, config).unwrap();
tracing::trace!("Persisted to {:?}", file_path);
});
}
}
}