Add init to lazy store

This commit is contained in:
Tony
2024-10-03 11:48:19 +08:00
parent 79bc8d08f4
commit bbd34b16f4
2 changed files with 9 additions and 2 deletions
+8 -1
View File
@@ -54,7 +54,7 @@ export class LazyStore implements IStore {
private readonly options?: StoreOptions
) {}
public get store(): Promise<Store> {
private get store(): Promise<Store> {
if (!this._store) {
this._store = createStore(this.path, this.options).catch(
async () => (await getStore(this.path))!
@@ -63,6 +63,13 @@ export class LazyStore implements IStore {
return this._store
}
/**
* Init/load the store if it's not already
*/
async init(): Promise<void> {
await this.store
}
async set(key: string, value: unknown): Promise<void> {
return (await this.store).set(key, value)
}