A newbie question – There is an async function inside a for loop and I want to keep collecting data and once done I want to use this information to do something. How do I perform this using a callback? I was able to achieve the same using async.whilist but I want to avoid it and understand basic callback better.
function kickoff() {
xlData.forEach(function(data) {
var ruleId = data.rule_id;
asyncRequest(ruleId).then(function(result) {
results.push(result);
});
});
}
I want to avoid doing this
function kickoff() {
async.whilst(
function test(cb) {
cb(null, i<len);
},
function iter(callback) {
i++;
asyncRequest(ruleId).then(function(result) {
results.push(result);
});
},
function (err, result) {
//able to get stuff that I can work with
console.log(result.length);
}
);
}