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

async parallel error handling #334

Closed
MichaelMcKavanagh opened this issue Jun 20, 2013 · 13 comments
Closed

async parallel error handling #334

MichaelMcKavanagh opened this issue Jun 20, 2013 · 13 comments

Comments

@MichaelMcKavanagh
Copy link

When processing multiple functions in parallel, using async parallel, if one of those functions throws an error via it's callback, async parallel processes it's callback before some of it's functions have completed. This may be the desired behaviour under some situations, however, I desire different logic. I would like all functions to run regardless of if some of them error or not, and then to be able to process through an error array after they have all completed processing.

My workaround for this situation currently is for my functions running in parallel to always not throw an error via normal way, but instead pretend they succeeded, and pass their error/data through an object in the result. In this way all of the functions will run, and then I have to manually process through the result objects looking for and handling any errors.

However, bypassing normal error handling in order to workaround async parallel isn't ideal in my mind. Perhaps there could be a better solution to provide either option for us, depending on the desired behaviour.

@lippling
Copy link

+1.
I have the same problem with the series/parallel function. I want to run several database queries and show partial results to the user.

@rlidwka
Copy link

rlidwka commented Jun 25, 2013

Just wrap these functions with your own functions that silently ignore/log errors.

Real-world example: https://github.com/rlidwka/sinopia/blob/master/lib/storage.js#L161 . As you can see, that function never returns error as first argument. You can do the same.

I don't see any problem here.

@daviddenton
Copy link

+1 for the feature request.

We've implemented a version which wraps async, called parallelCollect, which collects the errors into a dictionary that is passed to the final callback when all of the individual tasks have completed (in the same way as the successful results are passed if you give it named functions).

With regards to @rlidwka's comment - It's not that it's hard to implement - it's just a use case that many people would be useful in the core async library.

Don't mind doing the implementation myself via a pull request if it's not a waste of time.

@wshaver
Copy link

wshaver commented Aug 27, 2013

+1

@iliakan
Copy link

iliakan commented Aug 31, 2013

Can be done with a wrapper, but the task is generic, should be a ready-to-use async method for it.

@andrewwakeling
Copy link

+1.

It makes sense to present errors in the same structure as the results.

If 2 or more parallel callbacks throw errors, you only get the first error. Also, when the error is shown, you don't receive the results from the other successful callbacks.

@chmanie
Copy link

chmanie commented Mar 20, 2014

+1

@caolan caolan closed this as completed Mar 28, 2014
@Volox
Copy link

Volox commented Mar 31, 2014

It has been solved? Is now possible to collect errors of execute task regardless?

@reggi
Copy link

reggi commented Apr 22, 2014

Would love a better wrapper example in here / agreed upon solution. Bump 👍

@reggi
Copy link

reggi commented Apr 22, 2014

Is this what you guys meant by wrapper?

var collect = function(callback){
  return function(){
    var args = Array.prototype.slice.call(arguments);
    args.unshift(null);
    return callback(null, args);
  }
}

Then within the call: var callback = collect(callback);
Full example here https://gist.github.com/reggi/11186741

@HugoPoi
Copy link

HugoPoi commented Jul 3, 2014

+1

2 similar comments
@elebescond
Copy link

👍

@peterfirst
Copy link

+1

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
None yet
Projects
None yet
Development

No branches or pull requests