Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What local storage in html5 can I use safely in the browser ui thread and the web worker thread

I've been trying to use web sql database api in webkit based browsers. I have been using the async api in the main ui thread and a web worker. Both threads access the same database (which as you know is sqlite underthehood)

Everything behaves fine but occassionally transactions are lost or one transaction fails and it seems to be a timing/race condition. It appears access to the underlying sqlite database is not thread-safe.

A bit more background. My web worker is simply executing a query against a table that may have a record inserted into it from the main ui thread.

I am wondering if it is actually documented somewhere what local/web storage can be accessed safely from both the ui thread and the web worker thread? I've read somewhere that the indexeddb api is thread safe but that does not help me right now since browser support for it is poor/non-existent for the browsers I am targeting (at least I think so - I get my information from http://caniuse.com )

Any insights would be gratefully received

like image 264
paul Avatar asked Feb 15 '12 14:02

paul


1 Answers

You can't use localStorage or sessionStorage from WebWorkers.

While both are synchronous operations they aren't a real issue for simple data writing and reading. The issue is more relevant at browser start-up, but that's a browser implementation issue.

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

like image 148
Francisc Avatar answered Oct 22 '22 01:10

Francisc