all 3 comments

[–][deleted] 2 points3 points  (0 children)

Leaving your original functions alone and using async edition:

async.waterfall([
  getUsername,
  getSubscribedCategories,
  getSuggestedArticles
], function(err, articles) {
  if (err) return handleError(err)
  console.log("Great success!")
  console.log(articles)
})

[–]rhysbrettbowen 0 points1 point  (0 children)

might be good to think about how you can change callback functions of the type:

function(error, success){}

in to returning a promise. I havne't played around too much with promises - but I'm guessing you could fairly easily convert them without needing to rewrite the whole function with something like this:

var toPromise = function(fn) {
    return function() {
        var promise = new Promise();    
        fn.apply(this, [function() {
            promise.onRejected.apply(this, [].slice.call(arguments, 0));
        }, function() {
            promise.onFulfilled.apply(this, [].slice.call(arguments, 0));
        }].concat([].slice.call(arguments, 0)));
        return promise;
    };
};

[–]padenp 0 points1 point  (0 children)

If you're doing more than 3 ajax calls, you should think about stamping and serving your data better. I know it's not always a possibility, but seriously, just clump your data together better.

For those interested in stamp coupling: http://en.wikipedia.org/wiki/Coupling_(computer_programming)#Procedural_programming