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()
}
Currently
.update()
awaits only thethis.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.