Do not use forEach with async-await
TLDR: Use for...of
instead of forEach
in asynchronous code.
The problem
Array.prototype.forEach
is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)
For example, the following forEach loop might not do what it appears to do: