I'm using Async to call a function in which it asynchronously calls db and fetches some values then it returns that value to the callback of the async.series. But then how can I pass the value as a return
value of the outer function?
Please refer to the comments in the code below for more info.
getUserObjFromDb = function(username, cb) {
var user = {};
async.series([
function(callback){
var userObj = callDb(username);
callback( null, userObj );
}
],
function(err, results){
user = results[0];
cb(user);
});
}
var theUser = getUserObjFromDb(username, function(user){
return user;
}); // theUser is undefined because the outer function getUserObjFromDb did not return anything even though its callback returned, it was only the callback of the async.series which returned.
How can I get the value of user
inside passed to theUser
?
I could be doing all this completely wrong and there could be a much simpler approach, so any help would be appreciated. Thank you.