【发布时间】:2019-07-27 21:54:35
【问题描述】:
async/await和.then().catch()一起使用有什么坏处吗,比如:
async apiCall(params) {
var results = await this.anotherCall()
.then(results => {
//do any results transformations
return results;
})
.catch(error => {
//handle any errors here
});
return results;
}
【问题讨论】:
-
我想
anotherCall是.then打电话吗? -
抱歉,忘记了。现在添加它。
-
不,没有害处。您只是使用
await将承诺链的最终值传递给result变量。
标签: javascript node.js asynchronous promise async-await