In the previous recipe, we saw how to trigger multiple asynchronous functions before awaiting their results. We've also seen how well the Promise API and asyc
/await
operators work together. There are some situations where it is preferable to use the Promise API.
In this recipe, we'll see how to use Promise.all
to collect the result of multiple asynchronous operations.
This recipe assumes you already have a workspace that allows you to create and run ES modules in your browser. If you don't, please see the first two chapters.
- Open your command-line application and navigate to your workspace.
- Create a new folder named
04-06-Promise-all-collect-concurrently
. - Create three functions,
checkEngines
,checkFlightPlan
, andcheckNavigationSystem
that log a message when they start and return aPromise
that resolves totrue
if a random number is higher than a threshold after some timeout:
function checkEngines() { console...