What local storage in html5 can be safely used in the ui browser stream and web worker thread

I am trying to use the api website database in webkit based browsers. I used async api in mostly ui thread and web worker . Both threads access the same database (which, as you know, is sqlite underthehood)

Everything behaves normally, but sometimes transactions are lost or one transaction fails, and this seems to be a time / race condition. Access to the sqlite database does not seem to be thread safe.

A bit more background. My web worker simply queries the table, which may have a record inserted into it from the main ui stream.

I am wondering, is it really documented with what secure access to local / web storage can be obtained from both the ui thread and the web worker thread? I read somewhere that indexeddb api is thread safe, but that doesn’t help me now, since browser support for it is bad / nonexistent for the browsers I am targeting (at least I think so - I get information from http: / /caniuse.com )

Any ideas would be greatly appreciated.

+6
source share
1 answer

You cannot use localStorage or sessionStorage from WebWorkers.

Although both are synchronous operations, they are not a real problem for easily entering and reading data. This problem is more relevant when starting the browser, but the problem is with the implementation of the browser.

Take a look at this, this should help: http://www.nczonline.net/blog/2012/04/25/the-performance-of-localstorage-revisited/

+2
source

Source: https://habr.com/ru/post/908520/


All Articles