Console.log 在异步函数中不起作用
Console.log doesn't work in async function
我正在尝试在异步函数中记录一条语句,如下所示:
async generateCharts (insights) {
const { url } = await this.reportsClient.createReport(insights)
console.log('url from reports', url)
return this.parse(url)
}
虽然没有显示日志语句,但我确定这是因为异步功能。那是对的吗?无论如何要解决这个问题?
您的示例缺少上下文,但是,恕我直言,那是因为您的 createReport 函数从未执行过。
没有其他原因导致 console.log 不会被执行。
Note that errors are swallowed "silently" within an async function –
just like inside normal Promises. Unless we add try / catch blocks
around await expressions, uncaught exceptions – regardless of whether
they were raised in the body of your async function or while its
suspended during await – will reject the promise returned by the async
function.
我正在尝试在异步函数中记录一条语句,如下所示:
async generateCharts (insights) {
const { url } = await this.reportsClient.createReport(insights)
console.log('url from reports', url)
return this.parse(url)
}
虽然没有显示日志语句,但我确定这是因为异步功能。那是对的吗?无论如何要解决这个问题?
您的示例缺少上下文,但是,恕我直言,那是因为您的 createReport 函数从未执行过。 没有其他原因导致 console.log 不会被执行。
Note that errors are swallowed "silently" within an async function – just like inside normal Promises. Unless we add try / catch blocks around await expressions, uncaught exceptions – regardless of whether they were raised in the body of your async function or while its suspended during await – will reject the promise returned by the async function.