Answers for "foreach async typescript"

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

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 "Javascript"

Browse Popular Code Answers by Language