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 Task completed'); 
  }); 
  console.log('After Promise created');}  
  1. Start your Python web server and open the following link in your browser: http://localhost:8000/.
  2. You should see the following output:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.26.152