Using async/await with a forEach loop
Using async/await with a forEach loop Are there any issues with using async/await in a forEach loop? I'm trying to loop through an array of files and await on the contents of each file. async/await forEach await import fs from 'fs-promise' async function printFiles () { const files = await getFilePaths() // Assume this works fine files.forEach(async (file) => { const contents = await fs.readFile(file, 'utf8') console.log(contents) }) } printFiles() This code does work, but could something go wrong with this? I had someone tell me that you're not supposed to use async/await in a higher order function like this so I just wanted to ask if there was any issue with this. async/await 12 Answers 12 Sure the code does work, but I'm pretty sure it doesn't do what you expect it to do. It just fires off multiple asynchronous calls, but the printFiles functi...