【发布时间】:2019-05-24 05:46:58
【问题描述】:
大部分文章都提到await 是then 的替代品。但是,我找不到使用await 执行以下方法的方法,因为它将推迟执行直到run query 完成。只是好奇,有没有办法?
this.database
.run(query, bindings)
.then(result => this.ws.send(result))
.catch(err => this.ws.error(err));
return reply.code(202).send();
【问题讨论】:
-
不,在这种情况下
async/await并没有真正的帮助。 -
顺便说一句,我建议在这里使用
.then(…, …)instead of.then(…).catch(…)。
标签: javascript node.js promise async-await