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

134
Vistas
Transform async.parallel to async.auto

I have an async.parallel with 2 functions, and now I need to transform to async.auto or async.waterfall because I need to pass a value from the first function to the second.

Both functions return an array. In the second function the param timeAdjust will has the value from array1.timeAdjust

Can anyone help me?

The code:

router.get('/:machineID', function(req, res, next) {
    var machineID = req.params.machineID;

    async.parallel({
        one: function(callback){
            auxPrinters.function1(machineID, 'ent', function(array1){
                callback(null, array1);
            });
        },
        two: function(callback){
            auxPrinters.function2(machineID, 'ent', timeAdjust, function(array2){
                callback(null, array2);
            });
        },      
    },
    function(err, results){  //results.one=array1 & results.two=array2
        if(err) {console.log("****** ERROR:"); console.log(err);}
        else{
            console.dir(results);
            res.render('jobs', {title: 'Job Info', results});
        }
    });
});
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

here is your answer, but before that it is weird for me that you want to write array1.timeAdjust if array is an array, so I will just believe that array1 is an object

router.get('/:machineID', function(req, res, next) {
    var machineID = req.params.machineID;

    async.waterfall([
        function(callback){
            auxPrinters.function1(machineID, 'ent', function(array1){
                callback(null, array1);
            });
        },
        function(array1, callback){
            var result = {}
            result.one = array1
            timeAdjust = array1.timeAdjust
            auxPrinters.function2(machineID, 'ent', timeAdjust, function(array2){
                result.two = array1
                callback(null, result);
            });
        },      
    ],
    function(err, results){  //results.one=array1 & results.two=array2
        if(err) {console.log("****** ERROR:"); console.log(err);}
        else{
            console.dir(results);
            res.render('jobs', {title: 'Job Info', results});
        }
    });
});

as you can see I didn't pass array.timeAdjust but the full array1 since you want array1 and array2 at the final callback

about 4 years ago · Santiago Trujillo Denunciar

0

Final Solution:

async.waterfall([
        function(callback){
            console.log("****** ASYNC JOBS 1");
            auxPrinters.function1(machineID, 'ent', function(array1){
                callback(null, array1);
            });
        },
        function(array1, callback){
            console.log("****** ASYNC JOBS 2");
            auxPrinters.function2(machineID, 'ent', array1, function(array2){
                callback(null, array1, array2);
            });
        },      
    ],
    function(err, array1, array2){
        if(err) {console.log("****** ERROR ASYNC:"); console.log(err);}
        else{
            res.render('jobs', {title: 'Job Info', array1, array2});
        }
    });
about 4 years ago · Santiago Trujillo 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