1(async () => {
2 let response = await fetch('/article/promise-chaining/user.json');
3 let user = await response.json();
4 ...
5})();
1function hello() {
2 return new Promise((resolve,reject) => {
3 setTimeout(() => {
4 resolve('I am adam.');
5 }, 2000);
6 });
7}
8async function async_msg() {
9 try {
10 let msg = await hello();
11 console.log(msg);
12 }
13 catch(e) {
14 console.log('Error!', e);
15 }
16}
17async_msg(); //output - I am adam.