Skip to content

Node.js based forum software built for the modern web

changed to async.eachSeries

Baris Usakliff9990701b13
diff --git a/src/posts.js b/src/posts.js
index 3c9714b5bc..5a09ff0df8 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -107,28 +107,29 @@ marked.setOptions({
}
Posts.getPostsByPids = function(pids, callback) {
- var posts = [],
- loaded = 0;
-
- for(var i=0, ii=pids.length; i<ii; ++i) {
- (function(index, pid) {
- Posts.getPostData(pid, function(postData) {
-
- if(postData) {
- postData.relativeTime = utils.relativeTime(postData.timestamp);
- postData.post_rep = postData.reputation;
- postData['edited-class'] = postData.editor !== '' ? '' : 'none';
- postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
- postData.content = marked(postData.content || '');
- posts[index] = postData;
- }
-
- ++loaded;
- if(loaded === pids.length)
- callback(posts);
- });
- }(i, pids[i]));
+ var posts = [];
+
+ function iterator(pid, callback) {
+ Posts.getPostData(pid, function(postData) {
+ if(postData) {
+ postData.relativeTime = utils.relativeTime(postData.timestamp);
+ postData.post_rep = postData.reputation;
+ postData['edited-class'] = postData.editor !== '' ? '' : 'none';
+ postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
+ postData.content = marked(postData.content || '');
+ posts.push(postData);
+ }
+ callback(null);
+ });
}
+
+ async.eachSeries(pids, iterator, function(err) {
+ if(!err) {
+ callback(posts);
+ } else {
+ callback([]);
+ }
+ });
}
Posts.getPostField = function(pid, field, callback) {
diff --git a/src/topics.js b/src/topics.js
index bb53236273..a7c37f7cde 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -267,7 +267,7 @@ marked.setOptions({
Topics.getTeasers = function(tids, callback) {
var teasers = [];
if (Array.isArray(tids)) {
- async.each(tids, function(tid, next) {
+ async.eachSeries(tids, function(tid, next) {
Topics.getTeaser(tid, function(err, teaser_info) {
if (err) teaser_info = {};
teasers.push(teaser_info);
diff --git a/src/user.js b/src/user.js
index e32214f483..8dcc3f1b48 100644
--- a/src/user.js
+++ b/src/user.js
@@ -156,7 +156,7 @@ var utils = require('./../public/src/utils.js'),
});
}
- async.each(uuids, iterator, function(err) {
+ async.eachSeries(uuids, iterator, function(err) {
if(!err) {
callback(returnData);
} else {
@@ -556,7 +556,7 @@ var utils = require('./../public/src/utils.js'),
});
}
- async.each(uids, iterator, function(err) {
+ async.eachSeries(uids, iterator, function(err) {
callback(returnData);
});
}
@@ -641,7 +641,7 @@ var utils = require('./../public/src/utils.js'),
});
}
- async.each(uids, iterator, function(err) {
+ async.eachSeries(uids, iterator, function(err) {
callback(usernames);
});
}
@@ -660,7 +660,7 @@ var utils = require('./../public/src/utils.js'),
});
}
- async.each(uids, iterator, function(err) {
+ async.eachSeries(uids, iterator, function(err) {
callback(userslugs);
});
}