Here is one approach which is pretty interesting:
http://joseoncode.com/2012/06/24/messing-with-cps-in-js/

We are currently using iced-coffee-script in a project and I couldn't
be any happier, what you wrote would translate to:

if cod
  await trueFn defer(err, result)
else
  await falseFn defer(err, result)

#here do whatever you want with err or result.

And if you like the other notation:

await trueFn defer(err, result) if cond
await falseFn defer(err, result) unless cond

#do whatever you want with err or result

Cheers!
Gustavo

On Tue, Aug 7, 2012 at 1:44 PM, Dan Milon <[email protected]> wrote:
> True, that works on this simplified case, but there is more logic, depending
> on the cond, etc.
>
> I recall reading a blog post about having async if.
> like
> if (cond, trueFn, falseFn, doneFn)
>
> That was interesting.
>
> On 08/07/2012 07:47 PM, Mark Volkmann wrote:
>
>> On Tue, Aug 7, 2012 at 11:35 AM, Dan Milon <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>>     I am wondering which are the different patterns to handle cases like
>>
>>     var results
>>     if (cond) {
>>       async1(function (err, res) {
>>         results = res
>>       })
>>     }
>>     else {
>>       async2(function (err, res) {
>>         results = res
>>       })
>>     }
>>     // here need to do something with results.
>>
>>     The problem is obvious, but i cannot see any good way to overcome it.
>>
>>
>> How about this?
>>
>> var results;
>> var fn = cond ? async1 : async2;
>> fn(function (err, res) {
>>   results = res;
>>   // Do something with results here.
>> });
>> --
>> R. Mark Volkmann
>> Object Computing, Inc.
>> --
>> 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 [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to