I am using co
to run a generator function that does some scraping and cleansing of data. However, I never reach a certain part of the code after a loop. Here's what my code looks like:
function*(){
var url = "mongodb://" + config.host + ":" + config.port + "/" + config.db;
var db = yield MongoClient.connect( url );
for( var establishment in [ {"establishment_id": 16} ] ){
var establishment_type = establishment.id;
var response = yield getRestaurants( establishment_type );
var restaurants = JSON.parse( response.body ).restaurants;
// here we create our restaurants in "saveable" form
var saveableRestaurants = [];
for(var i = 0; i < restaurants.length; i++){
var saveableRestaurant = restaurants[i].restaurant;
saveableRestaurant._id = restaurants[i].restaurant.R.res_id;
// Remove unwanted fields
//... code removed for brevity ...
// convert cuisine string into its appropriate id form
var cuisines = saveableRestaurant.cuisines.split(",");
var ids = [];
for( var i = 0; i < cuisines.length; i++ ){
console.log("LOOKING UP ID FOR ", cuisines[i]);
var match = yield db.collection(CUI).findOne({"cuisine_name":cuisines[i].trim()});
console.log("ID FOR ", cuisines[i], " IS", match.cuisine_id);
ids.push( id );
}
// I NEVER REACH THIS LINE!!!!
console.log( "ALL IDS ", ids );
}
}
db.close();
}
I never reach the console statement towards the end of the function