node.js async await 配合Promise对象使用
生活随笔
收集整理的這篇文章主要介紹了
node.js async await 配合Promise对象使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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');
1
xxx
this is timeout
zhang
3
總結
以上是生活随笔為你收集整理的node.js async await 配合Promise对象使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成都大熊猫繁育基地停车场怎么收费
- 下一篇: 关于tornado的异步耗时操作假设