Answers for "foreach async not working"

3

ts await foreach loop

async function printFiles () {
  const files = await getFilePaths();

  await Promise.all(files.map(async (file) => {
    const contents = await fs.readFile(file, 'utf8')
    console.log(contents)
  }));
}
Posted by: Guest on July-24-2020
0

foreach async not working

async function printFiles () {
  const files = await getFilePaths();

  for (const file of files) {
    const contents = await fs.readFile(file, 'utf8');
    console.log(contents);
  }
}
Posted by: Guest on September-30-2020

Code answers related to "foreach async not working"

Code answers related to "Javascript"

Browse Popular Code Answers by Language