From 83ad4ab04259114aba99b13e5cf4c161548d8445 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 18 Jul 2015 14:21:51 -0400 Subject: [PATCH] waterfall --- src/topics/tags.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/topics/tags.js b/src/topics/tags.js index dfbdf5ab03..fe2e8d8ea2 100644 --- a/src/topics/tags.js +++ b/src/topics/tags.js @@ -206,19 +206,17 @@ module.exports = function(Topics) { Topics.updateTags = function(tid, tags, callback) { callback = callback || function() {}; - Topics.getTopicField(tid, 'timestamp', function(err, timestamp) { - if (err) { - return callback(err); + async.waterfall([ + function(next) { + Topics.deleteTopicTags(tid, next); + }, + function(next) { + Topics.getTopicField(tid, 'timestamp', next); + }, + function(timestamp, next) { + Topics.createTags(tags, tid, timestamp, next); } - - Topics.deleteTopicTags(tid, function(err) { - if (err) { - return callback(err); - } - - Topics.createTags(tags, tid, timestamp, callback); - }); - }); + ], callback); }; Topics.deleteTopicTags = function(tid, callback) { @@ -243,7 +241,9 @@ module.exports = function(Topics) { updateTagCount(tag, next); }, next); } - ], callback); + ], function(err, results) { + callback(err); + }); }); };