Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js async.series not working

This piece of code was taken straight out of the example from: https://github.com/caolan/async#seriestasks-callback

var async = require("async");
async.series([
    function() { console.log("a"); },
    function() { console.log("b"); }
], function(err, results){
    console.log(err);
    console.log(results);
});

However it doesn’t work. It stops after printing "a".

Is it a bug with the latest build of async module or my usage have some issue?

like image 247
Soyeed Avatar asked May 28 '12 03:05

Soyeed


1 Answers

The functions you provide in the array passed into async.series need to accept a callback parameter that the function calls when the task is complete. So you'd want to do this instead:

async.series([
    function(callback){ 
        console.log("a"); 
        callback();
    },
    function(callback){ 
        console.log("b");
        callback();
    }
]...
like image 85
JohnnyHK Avatar answered Oct 17 '22 21:10

JohnnyHK