Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
Messageports does not post Message

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:

  1. I do not get a response in the main file in the console log e.ports (it is an empty array)
  2. I can only run this once. running it a second time (its in a react component) gives me that error:

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!

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda