I have a webworker which does some long computing. to be able to get the Progress of the worker I want to send the progress from the webworker via MessageChannel to the main script. so in the main file I start and listen to the webworker like that.
var channel=new MessageChannel();
sunAnalysisWorker.onmessage = function (e) {
console.log("messageport message", e.ports)
setSensorValues(e.data)
}
sunAnalysisWorker.postMessage({
meshPlanes: meshPlanesTransferable,
sceneMesh: inputContextCopy,
scenarioMesh: inputScenarioCopy,
hours: hours,
days: days,
months: months,
rays: {
origins,
directions,
},
},[channel.port1]))
the webworker looks like that:
self.addEventListener(
'message',
async function (e) {
let normalizedValues = 0
// do a lot of work --->
e.ports[0].postMessage("test")
self.postMessage(normalizedValues)
}
)
doing that gives me two Problems I don't know how to solve:
Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Port at index 0 is already neutered.
so there is something quite wrong, but I cannot figure out what. is there anyone with an idea? Thank you so much!