- Open your command-line application and navigate to your workspace.
- Create a new folder named 04-01-creating-Promise-with-async.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js with an async function named someTask:
// main.js
async function someTask () {
console.log('Performing some task');
}
- 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');
}
- 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');}
- Start your Python web server and open the following link in your browser: http://localhost:8000/.
- You should see the following output: