1
In a controller, I have two HTTP requests:
function findProfessionalEmail(professional) {
EmailHunter.findProfessionalEmail(professional.company_name, professional.first_name,
professionalLastName).then(function (data) {
var score = data.data.data.score;
if (isProfessionalEmailScoreHigh(score)) {
vm.professional.email = data.data.data.email;
}
});
}
and
function checkAvailability(professional, callback) {
findProfessionalEmail(professional);
var cb = callback || angular.noop;
CheckAvailability.save(getCheckAvailabilityDTO(vm.professional), function () {
console.log('Success!');
return cb();
}, function (err) {
console.log('Erro!');
return cb(err);
}).$promise;
}
When invoking the second method "checkAvailability()", the system does not execute my request of the method "findProfessionalEmail()" before, and always executes the request of the method "checkAvailability()" first.
Why are you acting like this? How can I fix it?
The findProfessionalEmail method of Emailhunter awaits the answer of a Promise (which may take a while), whereas the "save" of "Checkavailability" passes a callback that runs on time. Apparently the way is to place a call to checkAvailability() in the Promise response.
– lfarroco