Node.js 承诺不还

Node.js Promise without returning it

我有一个在不返回 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)

只是 return 来自您创建 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
}

注意:我们通常会忽略错误信息,但有时它们包含有价值的信息。在你的错误中有一个 link http://。 goo.gl/rRqMUw 正好解释了这个 problem:d