I have a solution where i have 2 loops inside each other it looks like this:
function myFunc(types, pages, callback) {
var pageResults = [];
for (var i = 0; i < types.length; i++) {
var type = types[i];
for (var j = 1; j < pages; j++) {
getBikes(type, j, function(err, results, settings){
if(err) throw err;
var obj = {
results: results,
settings: settings
};
pageResults.push(obj);
});
};
};
return callback(pageResults);
});
var types = ["string1", "string2", "string3", "string4"];
var pages = 15;
myFunc(types, pages, function(pageResults){
console.log("done");
});
But this ends right away it returns after 1 loop in the types loop, and if i log the obj that i return from the inner function without returning a callback it will run all the way through.
Yes getBikes is a async call similar to ajax, but in nodejs, with a module called request.js