Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created July 24, 2015 17:07
Show Gist options
  • Save myndzi/d6841a0ca9afbd035c00 to your computer and use it in GitHub Desktop.
Save myndzi/d6841a0ca9afbd035c00 to your computer and use it in GitHub Desktop.
var request = Promise.promisifyAll(require('request'));
function getIssues() {
return request(options)
.spread(r, body) {
if (r.statusCode !== 200) {
console.log("unsuccessful status code!");
console.log(body);
return;
}
issues = issues.concat(body["issues"]);
maxResults = body["total"];
options.body.startAt += numToRequest;
if (issues.length < maxResults) {
return Promise.delay(timeToWaitAfterRequest).then(getIssues);
}
console.log("finished getting data, sorting it now");
listifyIssues(); // is this sync or async? assuming sync
return putIssuesInDatabase();
})
.catch(function (e) {
// the caller of getIssues should probably be catching and logging, not this function
console.log("Error!");
console.log(e);
// rethrow ?
})
}
getIssues().then(function (result) {
// result is the return from knex
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment