Having an issue, appreciate any help.
I'm trying to gather all my async functions together. Tried async.parallel, async.each, gather-gm. Nothing makes the final callback work. Here's the updated code(but yet not working properly):
var calls = [];
async.each(parser.allHrefs,function (href,callback) {
getHtml(href,function(err, add){
console.log("Passing data: " + href);
if(err){
return callback(err);
};
if(add){
calls.push(href);
};
return callback();
});
}, function (err) {
if(err){
console.log('something went wrong');
}else{
console.log('finished');
};
});
And the first function:
function getHtml(link, callback) {
httpreq.get(link, function(err, res) {
if(err) {
return callback(err);
}
if(res.statusCode >= 300) {
return callback(null, false);
} else {
//cut parsing code here...
return callback(null, true);
}
});
}
p.s.:I've updated the code couple times. In this example i've tried to use async.parallel. And the thing is when i even get no errors, i still dont get to the "getLocations" function. Code looks much more better than first versions, but still refuses to work correctly.
callbackregardless of outcome. If it's an error, pass the error to the callback.parallelis different fromeachbecause the first executes an array of functions and the second moves through an array and executes the same function for each element. The other thing is that gethtml is not returning a value so you aren't pushing anything into thecallsarray.