-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
As NodeJS and this particular API is async I'm trying to make fetching procedure 'end' state but have no experience enough and can't find a right way. Can you show me the right way to do so with current API?
async.parallel({
readCrunch: function(cb, results) {
console.log('\r\nStart Crunchbase Categories fetching...');
crunchCatsLoad({page: 1}, crunchCatsList);
return cb(crunchCatsList);
}
}, function (err, results) {
if(results) {
console.log(results,' crunchbase Categories fetched.');
console.log('Why you are "undefined"?');
}
if (err) {
console.log('ERRR: ', err);
}
});
var crunchCatsLoad = function(query, arrayReturn) {
var catsArray = [];
crunchbase.categories( { page: query.page }, function(error, cats) {
if (cats) {
var items = cats.data.items;
var next_page_url = cats.data.paging.next_page_url;
items.forEach( function(category, i) {
catsArray.push({
// some code
});
});
if ( next_page_url !== null ) {
query.page++;
console.log('Getting page ', query.page);
crunchCatsLoad({ page: query.page }, arrayReturn);
} else {
arrayReturn = catsArray;
console.log(catsArray.length, ' Crunchbase cats fetched.');
return arrayReturn;
}
}
});
};
Hope to hear an advice or best practice from you.
Metadata
Metadata
Assignees
Labels
No labels