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

201
Vistas
How to use async.eachSeries in nodeJS?

I want to iterate through a list of items in a synchronous manner and use the result of each step in the next step. I can someone correct/suggest the code logic which I am using?

const async = require('async')

async.eachSeries([1, 2, 3, 4, 5],
  function downloadChunk (chunkID, asyncCallback) {
    console.log(chunkID)
    const result = `This is a result from ${chunkID} call and should be used somewhere in ${chunkID + 1}`
    // How should I pass this result to next step
    asyncCallback()
  },
  function complete (err) {
    if (err) console.log('Error: ' + err)
    console.log('this is the end. All the variables have been used')
  }
)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can simply create a variable outside the async.eachSeries like so:

const async = require('async')
var result = null;

async.eachSeries([1, 2, 3, 4, 5],
    function downloadChunk (chunkID, asyncCallback) {
        console.log(chunkID)
        console.log('Result from previous call', result);

        // reassign new value to the result
        result = `This is a result from ${chunkID} call and should be used somewhere in ${chunkID + 1}`

        asyncCallback()
    },
    function complete (err) {
        if (err) console.log('Error: ' + err)
        console.log('this is the end. All the variables have been used')
    }
)
about 4 years ago · Juan Pablo Isaza Denunciar
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