I'm trying to send a time delay to my webworker so it counts to 10 seconds, then calls the script on my main file but can't get it to execute properly.
main.js (path: public/javascripts/main.js)
const worker = new Worker('webWorker.js');
const timer = 5000;
window.onload = function() {
worker.postMessage(timer);
}
worker.onmessage = e => {
test();
}
function test(){
console.log("timer worked");
}
webWorker.js (path: public/javascripts/webWorker.js)
this.onmessage = e => {
const trigger = setTimeout(e.data);
this.postMessage(trigger);
}
Where is this breaking down?
*Update - the issue is because my webWorker.js file isn't being found. Error GET http://localhost:3000/webWorker.js 404 (Not Found)
Have no clue why this is happening.