Answers for "ts await foreach loop"

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
4

foreach async typescript

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

C# foreach loop async but wait at end

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();
}
Posted by: Guest on April-27-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language