Add close store

This commit is contained in:
Tony
2024-10-03 10:09:43 +08:00
parent e0bbc6d72b
commit 4cb9d8de5e
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ export type StoreOptions = {
* @param path: Path to save the store in `app_data_dir`
* @param options: Store configuration options
*
* Throws if the store at that path already exists
* @throws If a store at that path already exists
*/
export async function createStore(
path: string,
+12
View File
@@ -463,6 +463,18 @@ impl<R: Runtime> Store<R> {
self.store.lock().unwrap().save()
}
pub fn close_store(self) {
let store = self.store.lock().unwrap();
let app = store.app.clone();
let collection = app.state::<StoreCollection>();
let stores = collection.stores.lock().unwrap();
if let Some(rid) = stores.get(&store.path).copied() {
drop(store);
drop(stores);
let _ = app.resources_table().take::<Store<R>>(rid);
}
}
fn trigger_auto_save(&self) -> crate::Result<()> {
let Some(auto_save_delay) = self.auto_save else {
return Ok(());