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

亡梦爱人 提交于 2019-12-23 09:32:24

问题


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


回答1:


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/



来源:https://stackoverflow.com/questions/9295433/what-local-storage-in-html5-can-i-use-safely-in-the-browser-ui-thread-and-the-we

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!