我有一个用例来解决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)
答案 0 :(得分:1)
只需从创建fire and forget
承诺的Promise回调中返回某些内容即可。
我猜测处理程序是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