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 ...