Created
October 8, 2016 03:04
-
-
Save albacoretuna/d7cb68c7149cc355ac37478f206202b0 to your computer and use it in GitHub Desktop.
Async/Await and Prmise.all example from http://stackabuse.com/node-js-async-await-in-es7/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const request = require('request-promise'); | |
const headers = { | |
'User-Agent': 'scottwrobinson' | |
}; | |
const repos = [ | |
'scottwrobinson/camo', | |
'facebook/react', | |
'scottwrobinson/twentyjs', | |
'moment/moment', | |
'nodejs/node', | |
'lodash/lodash' | |
]; | |
const issueTitles = []; | |
async function main() { | |
let reqs = repos.map(async function(r) { | |
let options = { url: 'https://api.github.com/repos/' + r, headers: headers }; | |
let body = await request.get(options); | |
let json = JSON.parse(body); | |
if (json.has_issues) { | |
let issuesOptions = { url: 'https://api.github.com/repos/' + r + '/issues', headers: headers }; | |
let ibody = await request.get(issuesOptions); | |
let issuesJson = JSON.parse(ibody); | |
if (issuesJson[0]) { | |
issueTitles.push(issuesJson[0].title); | |
} | |
} | |
}); | |
await Promise.all(reqs); | |
} | |
main(); | |
console.log(JSON.stringify(issueTitles)); | |
// results in : [] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment