Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion trying to wrap my head around "promises" - async vs Q
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andy  
View profile  
 More options Mar 25 2012, 4:42 am
From: Andy <delvarwo...@gmail.com>
Date: Sun, 25 Mar 2012 01:42:32 -0700 (PDT)
Local: Sun, Mar 25 2012 4:42 am
Subject: trying to wrap my head around "promises" - async vs Q

*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?)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.