8

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?

1 Answer 1

19

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();
    }
]...
Sign up to request clarification or add additional context in comments.

6 Comments

it works. But i wonder why in their wiki they mention it this way async.series([ function(){ ... }, function(){ ... } ]);
where is callback initialized here?
This function appears to work even when I replace callback with callbach. Why does it work like this?
@AndersonGreen The callback parameter is provided by the async framework when it calls your methods. It's saying to you: 'call this callback method when your function has completed its work'.
Whenever I invoke (one function using async.series) inside (another function using async.series), it calls the functions in the wrong order, as detailed here: stackoverflow.com/questions/12554017/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.