Skip to content

Instantly share code, notes, and snippets.

@kalmas
Created November 4, 2014 13:00
Show Gist options
  • Save kalmas/4c3c5ff8f9530dd5de33 to your computer and use it in GitHub Desktop.
Save kalmas/4c3c5ff8f9530dd5de33 to your computer and use it in GitHub Desktop.
/*
Example of
if() {
if() {
async()
}
}
then another async
using Q
*/
var callMeMaybe = function (a, b) {
var deferred = Q.defer();
if(a) {
if(b) {
callMe(function () {
deferred.resolve()
});
// Return our promise
return deferred.promise;
}
}
// Didn't have to do anything, return a resolved promise.
deferred.resolve();
return deferred.promise;
};
callMeMaybe(true, true).then(function () {
// The next thing
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment