There's more...

It's possible to refactor the main function so that the pre-check functions are executed implicitly. We can use the Array.prototype.map function to do this:

 export async function main() { 
  const prelaunchChecks = [ 
    checkEngines, 
    checkFlightPlan, 
    checkNavigationSystem 
  ]; 
  const checkResults = await Promise.all(prelaunchChecks.map((check) =>   check()); 
  const readyToLaunch = checkResults.reduce((acc, curr) => acc &&   curr); 
 
  if (readyToLaunch) { 
    console.log('All systems go, ready to launch: '); 
  } else { 
    console.error('Something went wrong, abort the launch: '); 
  } 
 

The highlighted section shows that the asynchronous functions are ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.