Last active
August 29, 2015 14:17
-
-
Save Termina1/57ef292f304fcaed4fe7 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
// длинный вариант | |
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); | |
}); | |
}); | |
} |
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
// предположим, что 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