Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda