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.
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 <[email protected]> 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 [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