when forEach ends async code example
Example 1: 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)
}));
}
Example 2: async foreach
[1, 2, 3].forEach(async (num) => { await waitFor(50); console.log(num);});console.log('Done');