I used async module for my project. This is my code in file 1
exports.check = function(option){
var object = {};
async.parallel([
function(callback){
if(!option.one){callback(null, true);}else{ callback(null, false);}
},
function(callback){
if(!option.two){callback(null, true);}else{ callback(null, false);}
},
function(callback){
if(!option.three){callback(null, true);}else{ callback(null, false);}
}
],
function(err, results){
if(results[0] && results[1] && results[2] ){
object.one = results[0];
object.two = results[1];
object.three = results[2];
object.total = true;
}else{
object.one = results[0];
object.two = results[1];
object.three = results[2];
object.total = false;
}
})
return object;
}
And This is code in file 2. I use function in file 1:
var isexit = db.check(option);
console.log(isexit);
A problem is console is 'undefined'. If I change code in file 1 to be the line (return object):
exports.check = function(option){
var object = {};
async.parallel([
function(callback){
if(!option.one){callback(null, true);}else{ callback(null, false);}
},
function(callback){
if(!option.two){callback(null, true);}else{ callback(null, false);}
},
function(callback){
if(!option.three){callback(null, true);}else{ callback(null, false);}
}
],
function(err, results){
if(results[0] && results[1] && results[2] ){
object.one = results[0];
object.two = results[1];
object.three = results[2];
object.total = true;
}else{
object.one = results[0];
object.two = results[1];
object.three = results[2];
object.total = false;
}
return object;
})
}
It will error. So How to return a funciton result in file 1. Pls help. Thanks so much!