-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async.tryEach #1365
Add async.tryEach #1365
Conversation
It doesn't say in the documentation what happens when there's an error in |
lib/tryEach.js
Outdated
} | ||
error = err; | ||
result = args; | ||
callback(args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the discussion in #1248. Should this be callback(!err)
? If the task returns an error and a partial result (e.g. {}
), the function should probably move onto the next task as opposed to returning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. It should be callback(!err)
. I'll change it today.
I would be in favour of resolving #1248 before moving forward with this PR. |
lib/tryEach.js
Outdated
* @memberOf module:ControlFlow | ||
* @method | ||
* @category Control Flow | ||
* @name series |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an fyi, some of the JSDoc tags were duplicated here.
@hargasinski I have fixed the issues you mentioned :) |
I think this is really cumbersome to expect people to implement with function nihTryEach(fns, done) {
var lastResult;
var lastError;
async.some(fns, function (fn, cb) {
fn(function(err, result) {
lastErr = err;
lastResult = result;
cb(null, !err);
});
}, function (err, anySucceeded) {
if (!anySucceeded) return done(lastError);
done(null, lastResult);
}
} It's slightly more complicated than @alFReD-NSH 's implementation. I also think the concerns in #1248 wouldn't affect this implementation, we can deal with those separately. I'd say this is good to merge as-is now. 👍 |
Released in v2.4.0! |
This adds async.tryEach which fixes what was requested in #687. I needed something with similar requirements. My use case was that I needed to get some data, which I could get it from 3 websites(with slightly different code for each) but sometimes they go down randomly.
The name might be reconsidered. We can't use
try
because it's a reserved word. I couldn't think of anything better.You guys might want to also review the documentation, English is not my first language.
As you can see I wrote tests covering most cases, and the coverage is 100% for the file.