DEV Community

Discussion on: Refactoring node.js (Part 1)

Collapse
 
paulasantamaria profile image
Paula Santamaría

Hi there! In that example, all functions (myAsyncFunction, myAsyncFunction2 and myAsyncFunction3), are async, which means that they return promises. So what const firtsOperation is storing is the promise returned by myAsyncFunction.

Finally, by awaiting Promise.all we're waiting for all promises to resolve.

If I wanted firstOperation to contain myAsyncFunction final result I should have wrote const firstOperation = await myAsyncFunction();
But the idea of that example was to illustrate how we can execute many async functions in parallel.

More info: MDN - Promise.all()