Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jportella93/7064c9abefb69a5ceead647f981429ab to your computer and use it in GitHub Desktop.
Save jportella93/7064c9abefb69a5ceead647f981429ab to your computer and use it in GitHub Desktop.
Async/await in .map
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