Using bluebird with undefined function callback success

I am using the bluebird library over memcached .

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

this function does not call a success callback in the second parameter, so it seems that the then (res) function is not being called.

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

Is there a way to handle an event with a failed event?

+6
source share
1 answer

The main problem is that you do not provide the timeout argument for memcached.setAsync , but it is a required argument for memcached.set . These two lines are equivalent:

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

Add a timeout argument, and your code should work as expected.

+4
source

All Articles