2 ms·
I have a large ClojureScript app (https://partsbox.io/ https://partsbox.io/) and I really, really wanted to use WebWorkers. I wanted to run larger tasks like in
by jwr 7y ago
I have a large ClojureScript app (https://partsbox.io/ https://partsbox.io/) and I really, really wanted to use WebWorkers. I wanted to run larger tasks like indexing for search, or pricing calculations in WebWorkers.
But it seems to me that Webworkers were designed with an extremely narrow use case in mind. The restrictions placed on them make them essentially useless for me. To do anything ever remotely useful, I would need to duplicate my entire database in web workers, and then communicate with them through a thin straw. Database updates would need to be performed both in the main app database and in web worker threads.
The way they are restricted, I just can't figure out how to make any meaningful use of them.
- dassurma 7y agoIndexedDB is shared between workers and main thread, in case that helps.
- jwr 7y agoIndeed, and it is something I'm looking at. But at the moment my database is really native Clojure data structures, which has fantastic advantages. I would need to start storing them in a "traditional" database, introducing additional layers, serialization, overhead and bugs.
- krn 7y ago> I would need to start storing them in a "traditional" database, introducing additional layers, serialization, overhead and bugs. If the app state is stored in a single atom, I would use localForage[1] (available as a cljsjs package[2]) to keep it in sync between web workers and the main thread. It would also make the app accessible offline. [1] https://github.com/localForage/localForage https://github.com/localForage/localForage [2] https://clojars.org/cljsjs/localforage https://clojars.org/cljsjs/localforage