for (const file of files) { const contents = await fs.readFile(file, 'utf8'); console.log(contents); }
async function printFiles () { const files = await getFilePaths(); await Promise.all(files.map(async (file) => { const contents = await fs.readFile(file, 'utf8') console.log(contents) })); }
public async Task RunAsync() { var tasks = new List<Task>(); foreach (var x in new[] { 1, 2, 3 }) { var task = DoSomethingAsync(x); tasks.Add(task); } await Task.WhenAll(); }