I want a while loop running forever and when i click on a button it stops. But, while the while loop is running i want to be able to do other things on the webpage. I tried this, but it doesn't work because while the loop is running the worker isn't able to receive any messages.
main.js
---------
let w = new Worker("workers.js");
document.getElementById("stop").onclick = function() {
w.postMessage("stop");
w.terminate();
w = undefined;
}
workers.js
------------
let a = true;
onmessage = function(e) {
a = false;
}
while(a)
{
console.log(1);
}