Where asyncBananaRequest
returns a promise -
function potentiallyAsync () {
if (cachedBanana) {
return asyncBananaRequest();
}
return ??cachedBanana??;
}
potentiallyAsync().then(function(banana){
//use banana
})
I want a banana, I might already have it cached. Is there a way for me to return the cached banana in the potentiallyAsync functionas a promise that immediately resolves with the cached bananas?
I'm currently using the Q lib packaged in Angular, but I'm hoping there's a generic implementation
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…