by PhrosTT · 13y ago · 0 comments
I've been staying sane through the use of the 'Q' promise package (https://github.com/kriskowal/q). For example, in the below code chunk any errors thrown in makeEmailConfirmation or sendEmailConfirmation will land in the .fail() catch block.
I believe using a promise system is the only way to avoid callback hell.
var deferred = Q.defer();
...
Storage.CustomLinks.makeEmailConfirmationLink(user)
.then(function(link) {
return Email.sendEmailConfirmation(user, link);
})
.then(function(result) {
deferred.resolve(result);
})
.fail(function(err) {
deferred.reject(new ServerError(err));
})
.end();
...
return deferred.promise;