How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 4-02-await-async-results.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  1. Create a main.js with an async function named getRandomNumber that returns a random number:
// main.js 
async function getRandomNumber () { 
   return Math.random(); 
} 
  1. Create an async function, main, that calls getRandomNumber, waits for the result, and logs out the value:
export async function main () { 
  console.log('before task'); 
  const result = await getRandomNumber(); 
  console.log('Received the value: %s', result); 
  console.log('after task completed'); 
}  
  1. Start you Python web server and open the following link in your browser:
    http://localhost:8000/.
  2. You should see the following output: