以下代码在运行时, 第一个方法并没有把结果传递到第二个方法, 请问是什么问题?
var Q = require("q");
var getEmailBySessionId = function (mongo_client, redis_client, sid){
var deferred = Q.defer();
redis_client.get('s:' + sid, function(err, email) {
if (!err){
deferred.resolve({db : mongo_client, email : email});
}else{
deferred.reject({err_code: -1});
}
});
return deferred.promise;
};
var getUsersCount = function (data) {
var db = data['db'];
var deferred = Q.defer();
db.collection.count({}, {}, function(err, count){
if (!err){
data['count'] = count;
deferred.resolve(data);
}else{
deferred.reject({err_code : -2});
}
});
return deferred.promise;
});
getEmailBySessionId(mongo_client, redis_client, sid)
.then(getUsersCount)
.done(console.log, console.error);