async function in a for loop code example
Example 1: async for loop
(async function loop() {
for (let i = 0; i < 10; i++) {
await new Promise(resolve => setTimeout(resolve, Math.random() * 1000));
console.log(i);
}
})();
Example 2: foreach async typescript
for (const file of files) {
const contents = await fs.readFile(file, 'utf8');
console.log(contents);
}