Async.series is said to execute the function sequentially, but it does not for me,
My code:
var mysql=require('mysql');
var async=require('async');
var con;
var EID=30;
var res;
async.series([
function(callback) {
console.log("inside first func");
con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'imd2'
});
callback();
},
function(callback) {
console.log("inside second function");
var sql = "select EName from users where EID=" + EID;
con.query(sql, function(err, rows) {
console.log("inside query");
res = rows;
});
callback();
}
],
function(err) {
console.log("third function");
if (err)
return next(err);
console.log(res);
});
console.log("hi");
and my output is
inside first func
inside second function
third function
undefined
hi
inside query
If i change the second function's callback inside the con.query() Then the output changes to
inside first func
inside second function
hi
inside query
third function
[ RowDataPacket { EName: 'AndhraPradesh' } ]
My expected output is
inside first func
inside second function
inside query
third function
[ RowDataPacket { EName: 'AndhraPradesh' } ]
hi
Correct me if i'm wrong, but the function(err) should be called at the last, and then "hi" should be displayed right?(from the definitions given) What should I do to get my expected output?
P.S "hi" is just a debug, there will be very important codes after async.series to be performed and it will not be best fit inside a new function inside async.series Thanks