Reputation: 5477
I understand the basics of the Q service but am having trouble implementing it. I have a series of events, the second which depends on the first returning.
Promise setup
var Q = require('q');
var dataPromise = getCustomerId();
dataPromise
.then(function(data) {
console.log('Success!', data);
getGUID(req, res, next);
}, function(error) {
console.log('Failure...', error);
});
};
getCustomerId()
var getCustomerId = function() {
var getCustomerIdOptions = {
options...
};
var deferred = Q.defer();
request(getCustomerIdOptions, function(err,resp,body){
if(err){
deferred.reject(err);
console.log(err);
return;
}else{
deferred.resolve(body);
}
return deferred.promise;
});
};
I think I'm returning the deferred promise correctly, but am returning an error that dataPromise does not have a "then" property, it is undefined.
Upvotes: 2
Views: 36
Reputation: 887453
You're returning the promise in the request()
callback.
The actual getCustomerId()
function doesn't return anything.
Upvotes: 2