How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 04-06-Promise-all-collect-concurrently.
  3. Create three async functions, checkEngines, checkFlightPlan, and checkNavigationSystem that log a message when they start and return a Promise that rejects an error if a random number is higher than a threshold, or resolve after some timeout:
 function checkEngines() { console.log('checking engine'); return new Promise(function (resolve, reject) { setTimeout(function () { if (Math.random() > 0.5) { reject(new Error('Engine check failed')); } else { console.log('Engine check completed'); resolve(); } }, 250) }); } function checkFlightPlan() { console.log('checking flight plan'); return new Promise(function ...

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.