Created
January 9, 2014 20:19
-
-
Save ajhekman/8341211 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
var yourAsyncTask; | |
yourAsyncTask = function() { | |
var deffered, failure, successful; | |
deffered = $q.defer(); | |
successful = 'what ever your success condition is'; | |
failure = 'what ever your failure condition is'; | |
/*here we're using setTimeout to make it asynchronous*/ | |
setTimeout(function() { | |
var result; | |
/* Asume longRunningTask is defined elsewhere*/ | |
result = longRunningTask(); | |
if (result === successful) { | |
deffered.resolve(result); | |
} | |
if (result === failure) { | |
return deffered.reject(result); | |
} | |
}); | |
/*deffered.promise returns immediately*/ | |
return deffered.promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment