Answers for "typescript foreach async await"

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

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
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
0

typescript foreach async await

export async function asyncForEach<T>(array: Array<T>, callback: (item: T, index: number) => void) {
        for (let index = 0; index < array.length; index++) {
            await callback(array[index], index);
        }
    }

await asyncForEach(receipts, async (eachItem) => {
    await ...
})
Posted by: Guest on October-21-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language