【发布时间】:2018-07-12 07:38:43
【问题描述】:
我在典型的 MVC 结构中设置了我的服务器。控制器中的函数要求我等待模型中的函数查询我的数据库时给出的承诺。如果查询返回一个promise,我怎么不需要等待呢?
//model - why don't I have to make this an async/ await function?
const findUser = (name) => {
const author = User.findOne({
where: {
firstName: name,
},
});
return author;
};
//controller
const getUser = async (ctx) => {
ctx.body = await messages.findUser(ctx.request.body);
};
【问题讨论】:
标签: javascript c# asp.net-mvc database async-await