Closed
Description
Hi ... I love async!! and use a lot of it, especially, I love compose.
Thank you for the great module!! However, I cannot find a control flow to try/error the callback, is there any control flow function can do the following thing?
That said, I have fn1
, fn2
, fn3
, all of them will callback an error or result, if fn1
get the result, then the control flow end, or continue to fn2
, then fn3
. For example, it might look like:
async.try( [
function(next){
do_first_try(param, function(err, res){
if (err) return next(err);
next(null, res); /// the control flow end, because we have result now
}
},
function(next){
do_second_try(param, function(err, res){
if (err) return next(err);
next(null, res); /// the control flow end, because we have result now
}
},
function(next){
do_third_try(param, function(err, res){
if (err) return next(err);
next(null, res); /// the control flow end, because we have result now
}
},], function( err, result) {
/// get the result whatever it comes from first try or third try, or err if no result
})
Activity
aearly commentedon Jan 5, 2015
Interesting, it's kind of like
series
, except with the inverse of how it handles errors. It definitely could come in handy.benpptung commentedon Jan 6, 2015
yes :) in fact, I am using
series
doing this now,done(res)
to stop the try/error and return the result ordone(null)
to continue the next try, but it is looking like an anti-pattern to callback.knoid commentedon Mar 27, 2015
+1
I'll try using
series
for now. Thanks for the tip.aearly commentedon Jun 2, 2015
After further thought -- is this any different from
retry
? This allows you to have a unique function for every try, but is that actually useful? This is also similar to #568benpptung commentedon Jun 2, 2015
I think
retry
is doing thesame task
to get a successful response from task no more than specific times before returning an error. . e.g. ping a server alive or not. I think it is different from the idea oftry/error
, in which, we can try different ways to get a successful result. e.g. the typical way to getXMLHttpRequest
in front-end.megawac commentedon Oct 31, 2016
Yeah 👍 I'd like this.
Add async.tryEach, Fixes caolan#687
Add async.tryEach, Fixes caolan#687