Are there any issues with utilizing async/await in a forEach loop? I'm attempting to loop through an array of files and anticipate the content of each file.
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, however, could something turn out badly with this? I had somebody reveal to me that shouldn't utilize async/await in a higher-order function like this, so I simply needed to inquire as to whether there was an issue with this.