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

142
Vistas
Run javascript generator with nodejs worker_threads

I use cartesian product to generate a very large amount of permutations which are then passed to some function. I created a generator

function* generateCartesianProduct(input) {
   yield ...
}

const items = generateCartesianProduct(['a', 'b', 'c'], ['e, f, g'], ...)

in my case, items is size of 10m+.

I wish to pass this to node worker threads using node-worker-threads-pool library.

const pool = new StaticPool({
  size: 8,
  task: filePathToMyWorker
});

so I try to pass items to worker and process them

for (const item of items) {
  (async () => {
    try {
      const output = await pool.exec(value, 1000);
      
      // do something with output
    } catch (e) {
      console.error(e);
    }
  })();
}

This does not work, because it seems that it wants to first execute for-loop and then pass data to pool. But my wish is to iterate through items and pass them to worked pool, so I can iterate and concurrently execute my worker.

Any ideas how to make this work?

about 4 years ago · Juan Pablo Isaza
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