node.js - Node.js Promise 不返回
问题描述
我有一个用例来解决 Promise 而不返回它。在内部捕获错误,但不希望调用者等待承诺解决。
doSomething()
{
Promise.resolve()
.then(() => {
// do something.
})
.catch(reason => {
this.logger.error(reason);
});
}
收到此错误:
(node:2072) Warning: a promise was created in a handler at internal/timers.js:439:21 but was not returned from it, see http://. goo.gl/rRqMUw
at Function.Promise.cast (.../node_modules/bluebird/js/release/promise.js:225:13)
解决方案
只需从创建 Promise 的 Promise 回调中返回一些内容fire and forget
。
我猜那个处理程序是doSomething
doSomething()
{
Promise.resolve()
.then(() => {
// do something.
})
.catch(reason => {
this.logger.error(reason);
});
return null //or anything else that's sensible
}
注意:我们通常会忽略错误消息,但有时它们包含有价值的信息。在您的错误中有一个链接 http://。goo.gl/rRqMUw 准确地解释了这个问题:d
推荐阅读
- php - 寻求帮助在 Scandir Php 列表中显示文件名
- 3d - Meshlab 平滑不保存在 OBJ 中
- javascript - Delay in Promise.all won't work if increase sleep time after call sleep function
- flutter - 如何获取动态数据表颤动的选定行索引
- java - 在 POST 请求中接受换行符
- angular - 垫日期范围日期选择器显示错误的值 - Angular
- node.js - 变量 counter1 具有空值
- github - GitHub 个人访问令牌范围仅用于从私有仓库获取发布数据
- git - 在 Windows 10 上安装 Git 时出现安装错误
- javascript - 如何检查用户是否在 pwa 或浏览器中