1function makePromise(x) {
2 return new Promise(resolve => {
3 setTimeout(() => {
4 resolve(x);
5 }, 1000);
6 });
7 }
8
9 async function asyncFunc() {
10 var x = await makePromise(1); // the function is paused here until the promise is fulfilled
11 console.log(x); // logs 1
12 return x;
13 }
14
15 const returnedProm = asyncFunc(); // the async func returns a promise
16
17
18 returnedProm.then((x) => console.log(x));
19 // This promise is fulfilled with the return value from the async func, so this logs 1