Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs: Async.series only executes the first function and stops

On executing the following code, only first function of the async.series executes.

var fs = require("fs");
var async = require("async");
var buffer = new Buffer(10);
var read = "";
var readByt;
async.series([      
    function(callback) {
         console.log("console: 1");
    },
    function (callback){
        console.log("console: 2");
    }
],function(){});

The output is given below:

c:\>node fr.js
}}}c:/log.txt
File closed successfully.

If the following is edited as mentioned below:

var fs = require("fs");
var async = require("async");
var buffer = new Buffer(10);
var read = "";
var readByt;
async.series([
    function(callback) {
         console.log("test");
    },
    function (callback){
        console.log("console: 1");
    }
   function (callback){
        console.log("console: 2");
    }
],function(){});

The output changes as below:

c:\>node fr.js
test

How do i get all the functions in the async.series to execute?

like image 681
overflower Avatar asked Sep 15 '26 02:09

overflower


1 Answers

I think you need to invoke the callback argument supplied in the array of functions to instruct the async module to invoke the next function.

like image 89
Elliot Avatar answered Sep 16 '26 16:09

Elliot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!