Indeed, you cannot get anything less than +1 indentation.

Thanks for your input!
danmilon.

On 08/08/2012 04:54 PM, Tim Caswell wrote:
On Wed, Aug 8, 2012 at 4:13 AM, Dan Milon <danmi...@gmail.com> wrote:
That will work, indeed, but it annoys me that indentation and code
readability gets fucked up. You have to follow code traces in order to
understand the ordering of execution.
Dan, you're not going to get any less indentation than my simple
example.  There has to be at least one level of indentation after your
callback no matter what unless you extend the language.

If it makes you feel better you can indent your conditional in one
level as well so that they are both one level deep.

What I was showing is that function statements hoist their value, so
you can call them before the line that defines them is executed.  This
means your program can execute in a top-down linear fashion without
ever nesting any more than one level deep for callbacks.

As far as what the async library provides, I have no idea, I've never
used it.      It will require at least one function block with a level
of indentation though.

I find using named functions and other clever uses of the language
itself provides just as clear code most the time and with a lot less
abstraction.

I already use async for other cases. Do you find any of its control flow
functions helpful for the if/else problem?

Thanks,
danmilon.



On 08/08/2012 05:56 AM, Tim Caswell wrote:
If there really are only two functions that have the same callback
signature, then it's super easy taking advantage of named function
value hoisting.

      if (cond) async1(onDone);
      else async2(onDone);

      function onDone(err, result) {
        // the function finished
      }

But I suspect the question involves more complicated cases in practice.

On Tue, Aug 7, 2012 at 9:44 PM, Andy <delvarwo...@gmail.com> wrote:
I would personally go with using promises.

var q = require('q');
q.ncall(function() {
     if(cond) {
         return async1(); // this is a promise
     }
     return async2(); // so is this
}).then(function(res) {
     // hooray! one of them finished
}).error(function(res) {
      // something went wrong!
});

--
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

--
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

--
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