Using finally to ensure an operation is performed
Error handling can get fairly complicated. There may be cases where you want to allow an error to continue bubbling up the call stack to be handled at a higher level. In those cases, you may also need to perform some cleanup tasks. Often this can mean resetting some shared resource, but it could also simply be logging the current state of the application.
In this recipe, we'll see how to use finally
to ensure that some code is executed, regardless of the error state.
Getting ready
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.
How to do it...
- 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...