I wonder what is the proper way to do this?
while(newList.length < 10){
async.series([
function(callback){
async.eachSeries(rest,function(id,next){
if(getDistance(myLoc,id) < 5){
newList.push(id);
}
next();
});
callback();
},
function(callback){
var size = 10 - newList.length
rest = getPlaces()
callback();
}], function(err,results){
if(err) console.log('error occured in : ' + err);
});
}
rest is populated by 10 new places every run, while the first step of the asyc process is to find out if the distance of the 10 places is within 5km, if its within 5 km, then it's added to newList, if not then we'll do another loop until it finds 10 places with its distance within 5km
while really the idea is to re-iterate until my newList is filled with 10 (places with distance < 10 km), when I try to run this, it went over everything just once and won't loop for the second run.