【发布时间】:2018-07-24 05:39:58
【问题描述】:
async function main() {
console.log("Start")
await Author.create({name: 'Some Guy'}, function (err, awesome_instance) {
console.log("This should be next, but its not")
});
console.log("This should be last, but it's not")
}
main()
最后的日志语句在第二个之前记录。如果我使用await,为什么会出现这种情况?
【问题讨论】:
-
你需要返回一个promise,一旦promise被解决,你就可以使用
.then。
标签: javascript mongoose ecmascript-6 async-await