我试图在NodeJS中的异步函数内部编写一个函数。 下面是我的示例脚本
module.exports = async function (context, req) {
var mydata = (async () => {
return "output needed"
}) ()
console.log(mydata)
}
预期输出为:需要输出
我得到的是:承诺{
有没有等到诺言实现的想法?
您需要等待MyData
返回的Promise
:
null
async function test(context, req) {
var mydata = (async () => {
return "output needed"
}) ()
console.log(await mydata)
}
test()