function getData(){return new Promise(function(resolve, reject){setTimeout(function(){var uname = 'zhang';console.log('this is timeout');resolve(uname);}, 1000);});}//await 配合 promiese 的 resolve 使用 就会真的等待 同步async function test(){console.log(1);var t = await getData();console.log(t);console.log(3);}test();console.log('xxx');
1xxxthis is timeoutzhang3