Created
November 4, 2014 13:00
-
-
Save kalmas/4c3c5ff8f9530dd5de33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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