I have ran into a similar problem when I was making some scripts to populate a database with some records. I had this "async loop" and wanted to wait for it to finish to show some messages and do some cleanup, but obviously the clean up was being executed before all the asynchronous tasks I've started in the .forEach had finished :(
My solution at the time was to take out the .forEach and make it something like this
Hey Burke, nice one!
I have ran into a similar problem when I was making some scripts to populate a database with some records. I had this "async loop" and wanted to wait for it to finish to show some messages and do some cleanup, but obviously the clean up was being executed before all the asynchronous tasks I've started in the
.forEach
had finished :(My solution at the time was to take out the
.forEach
and make it something like thisBut your solution is ways more elegant!