NathanaelA/nativescript-localstorage

Sync or Async lib?

j-d-carmichael opened this issue · 3 comments

Totally new to native script.. but my immediate question that i cannot answer from your readme:

Is this library synchronous like in the web browser?

Hi,

I guess it depends on what you mean. It acts just like the web browser; however behind the scenes it does NOT save the data to the disk instantly -- it is de-bounced to allow you to save multiple keys before it actually commits them to disk... This can speed up the app tremendously if you have large or multiple keys you are using.

I was meaning in the sense that the app is able to know when the data has been persisted or read.
Currently building a vuejs app with vuex-persist which doesn't play too nice with async functions, eg indexdb.

Well, the app will definitely know the value is read; it has to wait for the data to be read from the storage for it to return the value (i.e. sync).

Technically it can't know 100% when the value has been persisted because everything is saved in ram; and then in the background it saves it out after a small denounced amount of time (250ms). But for all practical purposes; the value when saved is saved, and it is available for immediate reading. ;-)

But this is the same issue with caches in the storage on any system; until a fsync occurs; it might not actually be written to your storage, and so any power loss could cause you to lose data...