Add close store

pull/1860/head
Tony 8 months ago
parent e0bbc6d72b
commit 4cb9d8de5e
No known key found for this signature in database
GPG Key ID: 34BDD3EA27824956

@ -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,

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

Loading…
Cancel
Save