【发布时间】:2020-03-30 21:18:55
【问题描述】:
我在 AWS Lambda 中有一个函数可以在 Stripe 中检索用户详细信息。但是函数之后的代码首先执行。我错过了什么?
在我的例子中,该函数调用一个返回客户对象的 Stripe 函数。
我认为 Stripe 函数的细节与这个特定问题无关——问题是我的 async/await 的结构:
module.exports.getUserName = async (event, context)=>{
[code to get customerId from stripe]
var customerName
await stripe.customers.retrieve(customerId, function(err, customer){
if (err){}
else{
customerName = customer.name
}
})
console.log('This should run after stripe.customers.retrieve')
}
现在 console.log 语句首先运行。我还尝试将 Stripe 函数包装在一个单独的异步函数中,并尝试添加 try/catch。但它还没有工作。
如何确定控制台日志语句在 stripe.customers.retrieve 之后运行?
【问题讨论】:
标签: node.js aws-lambda