相关疑难解决方法(0)

如何在Node.js UnhandledPromiseRejectionWarning中找到未处理的承诺?

来自版本7的Node.js具有async/await语法糖用于处理promises,现在在我的代码中经常出现以下警告:

(node:11057) UnhandledPromiseRejectionWarning: Unhandled promise 
rejection (rejection id: 1): ReferenceError: Error: Can't set headers 
after they are sent.
(node:11057) DeprecationWarning: Unhandled promise rejections are 
deprecated. In the future, promise rejections that are not handled 
will terminate the Node.js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)

不幸的是,没有提到缺少捕获的线.有没有办法找到它而不检查每个try/catch块?

warnings unhandled-exception node.js promise async-await

162
推荐指数
4
解决办法
5万
查看次数

如何同步确定JavaScript Promise的状态?

我有一个纯JavaScript承诺(内置实现或poly-fill):

var promise = new Promise(function (resolve, reject) { /* ... */ });

根据规范,Promise可以是以下之一:

  • '已定居'和'已解决'
  • '已定居'和'被拒绝'
  • "待定"

我有一个用例,我希望同步询问Promise并确定:

  • 承诺落户了吗?

  • 如果是这样,Promise是否已解决?

我知道我可以#then()用来安排Promise更改状态后异步执行的工作.我不是问怎么做.

这个问题具体是关于Promise状态的同步审讯.我怎样才能做到这一点?

javascript promise es6-promise

132
推荐指数
11
解决办法
4万
查看次数