foreach async TypeScript
for (const file of files) {
const contents = await fs.readFile(file, 'utf8');
console.log(contents);
}
Cruel Chinchilla
for (const file of files) {
const contents = await fs.readFile(file, 'utf8');
console.log(contents);
}
[1, 2, 3].forEach(async (num) => { await waitFor(50); console.log(num);});console.log('Done');
Array.prototype.forEachAsync = async function (fn) {
for (let t of this) { await fn(t) }
}
Array.prototype.forEachAsyncParallel = async function (fn) {
await Promise.all(this.map(fn));
}
async function printFiles () {
const files = await getFilePaths();
for (const file of files) {
const contents = await fs.readFile(file, 'utf8');
console.log(contents);
}
}