How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 04-01-creating-Promise-with-async.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js with an async function named someTask:
// main.js 
async function someTask () { 
   console.log('Performing some task'); 
} 
  1. Create a main that calls someTask and logs messages before and after someTask is executed:
export function main () { 
  console.log('before task'); 
  someTask(); 
  console.log('after task created'); 
}  
  1. Chain a then call off of someTask and log a message in the callback function:
export function main () { console.log('Before Promise created'); someTask().then(function () { console.log('After ...

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.