Skip to content
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

Looking for a way to not exit on async.parallel on error. #675

Closed
reggi opened this issue Dec 1, 2014 · 18 comments
Closed

Looking for a way to not exit on async.parallel on error. #675

reggi opened this issue Dec 1, 2014 · 18 comments
Labels

Comments

@reggi
Copy link

reggi commented Dec 1, 2014

Majority of my most recent use-cases involve async functions that aren't dependent on each other, and so when some async function breaks up top, the rest of my code doesn't execute. Wondering if there's a simple way to do something like this without being so obtrusive to the library / so much overhead. In this case I'd like to return false on error, so I'm building an object with every property intact, if something fails everything is else is still there, and false takes the broken async functions place.

var noError = function(func) {
  return function(callback) {
    func(function(err, value) {
      if (err) return callback(null, false);
      return callback(null, value);
    });
  }
}

var parallelNoError = function(functions, callback) {
  var newFunctions = {};
  for (var func in functions) {
    newFunctions[func] = noError(functions[func]);
  }
  return async.parallel(newFunctions, callback);
}

@aearly Would love your thoughts on this one too.

@reggi
Copy link
Author

reggi commented Dec 1, 2014

We can call it Surge to stick with the electrical theme?

@reggi
Copy link
Author

reggi commented Dec 1, 2014

Or perhaps a different route.

Instead of a whole new function, we could just wrap the individual functions in a async.surge, which will return something else on error.

async.surge(async.apply(fs.write, "file.txt"))

or

async.applySurge(fs.write, "file.txt")

@aearly
Copy link
Collaborator

aearly commented Dec 2, 2014

There's a whole bunch of async combinators you could write to more easily plug functions together. I like this one, for when you don't care about the error. Another one would be to make async functions plug into the async.filter and async.reject family -- only callback a boolean, and false if there's an error.

@aearly
Copy link
Collaborator

aearly commented Dec 2, 2014

Also, not sure about "surge" -- the theme isn't really electrical. async.parallel([ignoreError(fn)], calllback) something like ignoreError(fn) or withoutError(fn) or noError(fn).

@reggi
Copy link
Author

reggi commented Dec 2, 2014

Good feed back, thanks @aearly.

You don't think this should be included with async?

@aearly
Copy link
Collaborator

aearly commented Dec 2, 2014

I'd wait to see what other think. There's a lot of stuff that could go in the grab-bag that is async.

@prasad83
Copy link

prasad83 commented Dec 6, 2014

Having this as part of async would be great.
It would be nice to collect the errors like the results of each task in the parallel callback.

@aearly
Copy link
Collaborator

aearly commented Dec 11, 2014

I'm putting together a collection of auxilliary higher-order async helper functions: acomb. A function like this would be welcome if you want to make a PR. :)

@reggi
Copy link
Author

reggi commented Dec 11, 2014

@aearly Took a look at acomb, really neat!

@goloroden
Copy link

+1, would love to see an option to continue on errors, too (although I don't need it for parallel, but for forEach).

@danielshir
Copy link

+1 for continuing on errors.
I have encountered a case where some functions running in parallel() will require cleanup code to run after completion. The current design scheme makes it hard to do so if an error occurs.

@colinmegill
Copy link

+1

5 similar comments
@oillescas
Copy link

+1

@skilledDeveloper
Copy link

+1

@fizerkhan
Copy link

+1

@levino
Copy link

levino commented Jan 21, 2016

+1

@jvillanti
Copy link

+1

@aearly
Copy link
Collaborator

aearly commented Feb 16, 2016

Closing this in favor of #942 . There's also the PR: #1012

@aearly aearly closed this as completed Feb 16, 2016
ipyramiddev added a commit to ipyramiddev/async-300 that referenced this issue Dec 10, 2022
How to continue *parallel* processing in case of a failing task seems to be a frequently asked question. It was mentioned in several issues:

- caolan/async#334
- caolan/async#675
- caolan/async#798
- caolan/async#942

Adding a hint to the documentation might help users of the library to find out about the answer to this question.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests