electron-userland / electron-json-storage

:package: Easily write and read user settings in Electron apps
1.43k stars 79 forks source link

Retry write if resulting file size is zero when using validate=true #128

Closed jviotti closed 4 years ago

jviotti commented 5 years ago

See: https://github.com/electron-userland/electron-json-storage/issues/123

Nantris commented 4 years ago

@jviotti I think this would be a great addition to the project.

jviotti commented 4 years ago

@Slapbox I think the main problem with this is that you could get into update conflicts if two entities are trying to write to the same key. Each of them may re-read what they wrote, just to find that the other entity over-wrote it already (this is coming up in the test failures).

Maybe we can add it, but as an opt-in feature behind an option flag?

jviotti commented 4 years ago

@Slapbox I added it behind a validate: true option in .set()

jviotti commented 4 years ago

Landed in v4.2.0

Nantris commented 4 years ago

@jviotti thanks for the crazy fast reply and merge!

That makes a lot of sense regarding possible interference between two atomic write attempts to the same key. I didn't look closely enough at the PR to realize it's checking for equality rather than just a non-zero size. Looks good though!