The variables firstOperation, secondOperation, and thirdOperation include the results of each function NOT the functions themselves. So the array you pass to Promise.all does not have functions as its elements, but the results of those functions.
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.
I think there's a mistake in this piece of code:
const firstOperation = myAsyncFunction();
const secondOperation = myAsyncFunction2('test');
const thirdOperation = myAsyncFunction3(5);
await Promise.all([ firstOperation, secondOperation, thirdOperation ]);
The variables firstOperation, secondOperation, and thirdOperation include the results of each function NOT the functions themselves. So the array you pass to Promise.all does not have functions as its elements, but the results of those functions.
Hi there! In that example, all functions (
myAsyncFunction
,myAsyncFunction2
andmyAsyncFunction3
), are async, which means that they return promises. So whatconst firtsOperation
is storing is the promise returned bymyAsyncFunction
.Finally, by awaiting
Promise.all
we're waiting for all promises to resolve.If I wanted
firstOperation
to containmyAsyncFunction
final result I should have wroteconst 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()