Skip to content

Instantly share code, notes, and snippets.

@Termina1
Last active August 29, 2015 14:17
Show Gist options
  • Save Termina1/57ef292f304fcaed4fe7 to your computer and use it in GitHub Desktop.
Save Termina1/57ef292f304fcaed4fe7 to your computer and use it in GitHub Desktop.
// длинный вариант
function getValue(id, cache, retrieveValue) {
return new Promise(function(ful, rej) {
if(cache.has(id)) {
ful(cache.get(id))
} else {
rej(false);
}
}).catch(function() {
return new Promise(function(ful, rej) {
retrieveValue(id, ful, rej);
});
});
}
// предположим, что cache и retrieveValue возвращают Promise
function getValue(id, cache, retrieveValue) {
return cache.get(id)
.catch(() => return retrieveValue(id));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment