In a prior recipe, we saw how to use Promise.all
to collect the results of multiple asynchronous functions. In an error state, Promise.all
is even more interesting. Often, when dealing with multiple possible error conditions, we have to write a log of Boolean logic if we want to display multiple error messages. But, in this recipe, we'll see how we can use Promise.all
and try-catch
blocks to handle multiple error conditions concurrently, without complicated Boolean logic.
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
async
functions,checkEngines
,checkFlightPlan
, andcheckNavigationSystem
that log a message when they start and return aPromise
that rejects an error...