Skip to content

Instantly share code, notes, and snippets.

@fennb
Created August 4, 2011 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fennb/1124580 to your computer and use it in GitHub Desktop.
Save fennb/1124580 to your computer and use it in GitHub Desktop.
Asynchronous loop issues illustrative example
// Illustrative case
for (var i = 0; i < recentBlogPostIds.length; i++) {
var blogPostId = recentBlogPostIds[i];
var results = [];
// Fetch from DB
asynchronousDB.getBlogPostById(blogPostId, function(err, post) {
htmlFragment = templating.render(post);
results.push(htmlFragment);
});
}
// Return results
return results;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment