Search code examples
javascripthtmllocal-storageweb-workerbrython

How to deliver information to webworker when it requests it


I have a piece of code that needs to execute on a webworker which needs to get feedback from something in the main thread (basically a get operation from a KVS). Unfortunately, I cannot use local storage because it is not accessible from a webworker. Is there any other way I can convey information from the main thread to the webworker such that when the webworker wants this piece of information, it can have it?

Another note is that I am using brython for everything, and I'm not sure if that prevents me from using traditional JavaScript solutions like IndexedDB. Guidance would be much appreciated.


Solution

  • SharedArrayBuffer is a way to share memory between the main thread and webworker.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer