Async Await - quan1997ap/angular-app-note GitHub Wiki
Async / Await
- KHông dùng map, forEach cho async await.
array.map((element, index, array) => { /* … */ })
array.forEach((element, index, array) => { /* … */ })
Có 3 elements được trả về lần lượt là elements, index, và array ban đầu như vậy chứng tỏ rằng forEach không chờ asynchronous process trong callback. Điều đó có nghĩa là, forEach mà bạn sử dụng không xây dựng trong quá trình asynchronous.
forEach / for - of loop item
for (const file of files) {
const contents = await fs.readFile(file, 'utf8');
console.log(contents);
}