I am looking to streamline the execution of a complex calculus operation within a web worker.
My challenge lies in retrieving a variable value from the main process while running the computation in the web worker.
To simplify, consider having two variables "a" and "b" in the main process.
The goal is to execute the following code solely by passing the "a" value:
worker.postMessage(a)
In the worker script, the logic would resemble something like this:
if (a<10) {
postMessage('result is true');
} else {
b = "request the value of b from the main process"
if (a*b < 20 ) {
postMessage('result is true');
} else {
postMessage('result is false');
}
}
A potential solution could involve setting up a websocket in the main process to provide variable values. However, I am open to exploring simpler or more efficient alternatives.
Thank you for any insights!