Created
February 11, 2015 21:15
-
-
Save cfv1984/239ef6f0a69987687d27 to your computer and use it in GitHub Desktop.
Caching a promise in a reproduceable way
This file contains 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
function cachedPromising(){ | |
var def = $q.defer(); | |
if(!cachedPromising.cached_value) | |
promising().then(function(data){cachedPromising.cached_value = data; def.resolve(cachedPromising.cached_value) }); | |
else def.resolve(cachedPromising.cached_value); | |
return def.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment