ECMAScript Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 03-01-creating-and-waiting-for-promises.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js file that creates a promise and logs messages before and after the promise is created, as well as while the promise is executing and after it has been resolved:
// main.js 
export function main () { 
 
  console.log('Before promise created'); 
 
  new Promise(function (resolve) { 
    console.log('Executing promise'); 
    resolve(); 
  }).then(function () { 
    console.log('Finished promise'); 
  }); 
 
  console.log('After promise created'); 
} 
  1. Start your Python web server and open the following link in your browser:
    http://localhost:8000/.
  1. You will see the following output: