Created
May 20, 2014 16:08
-
-
Save ELLIOTTCABLE/37979fc70447d2b749b7 to your computer and use it in GitHub Desktop.
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
return redis.smembersAsync('langs') | |
.then(function(languages){ | |
// I need to call `articleExists('foo', language)` for each member of `languages`. | |
// `articleExists` returns a promise; if it does, indeed, exist, then the promise resolves to | |
// the result I need (a name.) | |
// if the article does *not* exist, then the promise returned by `articleExists` is rejected, | |
// and I need to move on to the next element of `languages` | |
} |
petkaantonov
commented
May 20, 2014
Procedural
var article = Promise.reject(new Promise.RejectionError("not found"));
languages.forEach(function(lang) {
article = article.error(function(e) { return articleExists('foo', lang); });
});
return article;
Functional
return languages.reduce(function(article, lang) {
return article.error(function(e) { return articleExists('foo', lang); });
}, Promise.reject(new Promise.RejectionError("not found")));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment