Created
July 30, 2018 15:40
-
-
Save jportella93/7064c9abefb69a5ceead647f981429ab to your computer and use it in GitHub Desktop.
Async/await in .map
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
async function printFiles () { | |
const files = await getFilePaths(); | |
await Promise.all(files.map(async (file) => { | |
const contents = await fs.readFile(file, 'utf8') | |
console.log(contents) | |
})); | |
} | |
/// koa example | |
const getPictures = async (ctx, pictureList) => { | |
// for each item of the array, make a fetch | |
const pictures = await Promise.all(pictureList.map(async p => { | |
let picture = await axios.get(`//endpoint`) | |
return picture | |
})) | |
ctx.body = pictures | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment