javascript - Console.log 在异步函数中不起作用

标签 javascript async-await ecmascript-2017

我正尝试在异步函数中记录一条语句,如下所示:

async generateCharts (insights) {
  const { url } = await this.reportsClient.createReport(insights)
  console.log('url from reports', url)
  return this.parse(url)
}

虽然没有显示日志语句,但我确定这是因为异步函数。那是对的吗?无论如何要解决这个问题?

最佳答案

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.

javascript-async-await#error-handling

关于javascript - Console.log 在异步函数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41941248/

相关文章:

javascript - 如何在方法函数中将参数传递给 vue.js 路由器?

javascript - 如何列出 props 变量中的项目?

c# - 为什么任务甚至在等待中完成

reactjs - 当谷歌显示空白页面时获取 - Reactjs

javascript - 处理用于加载 .gif 图像的异步函数的正确方法是什么?

javascript - 将一组对象转换为数组项

javascript - 为什么我的模块的执行顺序与预期不同?

javascript - NodeJS Promise.all 正在等待所有组件完成后再继续

c# - List.Add 未完美添加并行和异步

JavaScript async 函数,当返回 promise 在没有返回值的情况下 resolved