Skip to content

Instantly share code, notes, and snippets.

@cfv1984
Created February 11, 2015 21:15
Show Gist options
  • Save cfv1984/239ef6f0a69987687d27 to your computer and use it in GitHub Desktop.
Save cfv1984/239ef6f0a69987687d27 to your computer and use it in GitHub Desktop.
Caching a promise in a reproduceable way
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