-
Notifications
You must be signed in to change notification settings - Fork 521
Add Task.whenAllResult to collect results of multiple parallel tasks #46
Add Task.whenAllResult to collect results of multiple parallel tasks #46
Conversation
Re: Task.whenAllTResult This seems to make a drastic change to It would be better to call public static Task<List<TResult>> whenAllTResult(final List<Task<TResult>> tasks) {
return whenAll(tasks).onSuccess(
// Get the results from tasks and return them in one list.
);
} This would prevent holding on to any unwanted references. Re: Task.whenAllResult I'm not sure we need this as I don't see many people needing to read the results of many tasks with different types and if they do, they can write one-off code like above. Additionally, it's not part of the .NET spec. We can remove this and rename Re: AggregateException I'm sorry about the List vs array change. This has been amended in #47 and it would be great to hear your thoughts on it. |
@grantland thanks for the feedback, will remove Task.whenAllResult and the changes to AggregateException and leave those for issue #47 I'll also make the recommended changes to whenAllTResult |
@grantland updated |
Looks perfect! Once you squash your commits, I'll accept the PR. |
Squashed |
* <p/> | ||
* If any of the supplied tasks completes in a faulted state, the returned task will also complete | ||
* in a faulted state, where its exception will resolve to that {@link java.lang.Exception} if a | ||
* single task fails or an {@link AggregateException} of all the {@link java.lang.Exception}s |
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.
AggregateException
will not only have java.lang.Exception
, right? It might have java.lang.Error
(basically it contains java.lang.Throwable
)
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.
For now I think it's fine as we only catch Exception
s right now. If/when we change it to Throwable
s, we'll change the documentation as well.
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.
Would we ever want to catch raw Error or Throwable? That would result in things like OOM error getting trapped rather than tearing down the process.
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.
More or less to match with newer Java APIs as well as other libraries: ReactiveX/RxJava#296
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.
I'm both for and against. If it is implemented, a few errors need to be caught specially to make sure they are not swallowed. Also unobserved exception handling should probably be a pre-requisite for merging that change in order to ensure import errors are not forgotten about.
What happens if the users code encounters a StackOverflowError? We attempt to catch it, then most likely (if user code is running on the same thread) we encounter another StackOverflow attempting to run through the continuations. Except this time, the error comes from Task code so it looks like a library issue and the original error information is lost.
IMO the current situation already traps more things than it should, things like IllegalStateException and NullPointerException which we shouldn't - these errors indicate a programming mistake, not an execution failure and so they should not pollute the user error handling flow like they do currently.
However, too many developers have (over-)used RuntimeExceptions to indicate conditions that should not really crash a program because it saved time thinking about error handling so I don't think it's realistic to change that.
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.
One comment, otherwise LGTM |
Add Task.whenAllResult to collect results of multiple parallel tasks
Creates a task that completes when all of the provided tasks are complete.
If none of the tasks faulted and none of the tasks were cancelled, the resulting task will end completed. The result of the returned task will be set to a list containing all of the results of the supplied tasks in the same order as they were provided (e.g. if the input tasks collection contained t1, t2, t3, the output task's result will return an
List<TResult>
wherecode list.get(0) == t1.getResult(), list.get(1) == t2.getResult(), and list.get(2) == t3.getResult()}
.