Well, I thought I understand Promises already, but seems I am missing something on this...
var redisPromise = new Promise(function(resolve, reject) {
redisClient.on('error', reject);
redisClient.on('ready', resolve);
}).then(function() {
// THIS ISN'T CALLED - CORRECT
log.enabled && log('connected, version: %s', redisClient.server_info.redis_version);
return redisClient;
}).catch(function() {
// THIS GETS CALLED - CORRECT
log('failed connecting to database:', e.message);
});
redisPromise.then(function() {
log("This shouldn't be called when connection fails");
});
For the case when connection to Redis fails I would expect the returned Promise to be rejected. However for some reason it's fulfilled. Am I missing something here?
I am using Bluebird implementation. Could it be possibly some bug in there ? I kinda doubt that, it all seems very well documented and making sense ... on paper.
RESOLVED
Full discussion at https://github.com/petkaantonov/bluebird/issues/156