Solution 1 :

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

Problem :

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.


Comment posted by StackSlave

const worker = new Worker('sendToPage.js'); worker.postMessage(someJSONHere);

Comment posted by kmindspark

Thanks for the info, but what if there is previous onmessage code that is being run on the webworker? Would this message still be received, or would we have to wait for the original code to finish? What if I want this message to be received despite there being previous onmessage handlers currently running.