Skip to content
Advertisement

How to wait for Promise.all() to complete before reaching next line?

I’m learning Node.js.

I have to call an async function work() inside my Promise.all() loop and it must be completed before moving on to statements that are after the Promise.all(). Currently, it reaches the FINISH statment before completing work().

What is the right way to make the code wait for work() function to complete?

JavaScript

Advertisement

Answer

It’s hard to tell what you’re really after here, but don’t mix and match await and then, in general.

JavaScript

prints out (the first lines with various delays)

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement