使用具有未定义的成功回调函数的蓝鸟

using bluebird with undefined success callback function

我正在使用 bluebird library over memcached

memcached.set('foo', 'bar', 10, function (err) { /* stuff */ });

此函数不会在第二个参数中调用成功回调,因此似乎没有调用 .then(res) 函数。

 Promise.promisifyAll(memcached);
 memcached.setAsync(hashedCacheKey, obj).then(function (res) {
            resolve(res);
        }).catch(function (err) {
            reject(err, null);
        });

我有什么办法可以处理未调用的成功事件吗?

这里的主要问题是您没有为 memcached.setAsync 提供超时参数,但它是 memcached.set 的强制性参数。这两行是等价的:

memcached.set("foo", "bar", () => { /* this is never called */ });
memcached.setAsync("foo", "bar").then(() => { /* this is never called, either */ })

添加超时参数,您的代码应该会按预期运行。