*Note, I am not asking which tool is better, I am simply trying to 
understand the differences.

*I'm trying to wrap my head around promises in node. Right now I'm writing 
all my code in callback soup. I am researching libraries and I found 
async<https://github.com/caolan/async>(duh) but I also found the horribly named 
but seemingly very popular 
q <https://github.com/kriskowal/q>.

What I am trying to figure out is if these libraries are mutually 
exclusive. The async page mentions nothing about "promsies" and instead 
talks about "flow control." But it seems like both libraries are sugar for 
handling async function flow and callbacks. Do they both solve the same 
problem, or can / should they be used together?

Take this example:

async.waterfall([
    function(callback){
        callback(null, 'one', 'two');
    },
    function(arg1, arg2, callback){
        callback(null, 'three');
    },
    function(arg1, callback){
        // arg1 now equals 'three'
        callback(null, 'done');
    }
], function (err, result) {
   // result now equals 'done'    
});


vs:

Q.call(step1).then(step2).then(step3).then(step4).then(function (value4) {
    // Do something with value4}, function (error) {
    // Handle any error from step1 through step4}).end();


Both libraries are doing things in a series, and both are passing their 
results to the next function. Is there really any difference between the 
two results other than Q returning a promise that you can chain to with 
.then? 

Is async really just a more versatile q? Or are there reasons to use one 
and the other and they could be used together?

And can you do parallel functions with promises? Or is that not what 
they're used for? (And if not, should you use async + q, or is there too 
much overlap?)

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to