【发布时间】:2020-12-16 00:05:42
【问题描述】:
我找到了一些如何使用 await 返回值的示例,但我的异步函数中有一个函数,但没有找到如何在 ad.authenticate 中传递 auth 的结果的解决方案强>。这是我所拥有的:
async function authorize(username, password){
ad.authenticate(username, password, function(err, auth){
console.log("auth: " + auth);
});
}
router.post('/ldapauth',function(req,res){
var username = req.body.username;
var password = req.body.password;
authorize(username, password)
.then(result => {
console.log("result: " + result)
res.status(200).send({
result: result,
});
}).catch(err => {
console.log(err);
})
});
router.post 中的结果是未定义的,因为我相信它在 auth 函数有机会返回 auth 值之前被调用?
Console:
result: undefined
auth: true
【问题讨论】:
标签: node.js express asynchronous async-await