-
-
Notifications
You must be signed in to change notification settings - Fork 954
Open
Description
Currently .update()
awaits only the this.write()
operation. It would be nice for it to also await the passed callback which mutates the state. Without the await, the persisted value could occur before the callback finishes its mutation.
// before
async update(fn: (data: T) => unknown): Promise<void> {
fn(this.data)
await this.write()
}
// after
async update(fn: (data: T) => unknown): Promise<void> {
const result = fn(this.data);
if (result instanceof Promise) {
await result;
}
await this.write()
}
Metadata
Metadata
Assignees
Labels
No labels