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

WhenAll exits early when any task has an exception #514

Open
all-iver opened this issue Oct 22, 2023 · 4 comments
Open

WhenAll exits early when any task has an exception #514

all-iver opened this issue Oct 22, 2023 · 4 comments

Comments

@all-iver
Copy link

It seems as though WhenAll immediately fails with an exception if any awaited task throws an exception, instead of waiting for all the tasks to complete and then throwing the exception. I believe this is different than normal Task behavior which would wait until all tasks are completed regardless of whether some of them failed.

This was unexpected behavior for me because I am expecting some tasks to fail occasionally, but I still need to know that all tasks are done before continuing. I understand from #335 that WhenAll doesn't store the exceptions for individual tasks, but I think it should not convert to WhenAny just because one task failed...perhaps it could store the first exception that happened and then re-throw that when all tasks are done?

Or, is there some way I'm missing to wait for all tasks to complete regardless of failure?

@neuecc
Copy link
Member

neuecc commented Oct 22, 2023

Yes, the reason WhenAll behaves differently than Task.WhenAll is due to a failure in my initial design.
I would like to fix it, but am having trouble thinking of a way to do so because it would break compatibility.

@timcassell
Copy link

timcassell commented Oct 22, 2023

If it helps, I recently solved this problem in my promise library by adding Promise.AllSettled to match the javascript method. You could do the same by adding WhenAllSettled.

@andreiagmu
Copy link

Has anyone checked out this solution? (by @adammyhre)
https://gist.github.com/adammyhre/40e7c968edda098fdebb2adbe806c911

Source, see Important Notes 4) in the video description:
https://www.youtube.com/watch?v=OlNJ2GkaPTE

@hmkc
Copy link
Contributor

hmkc commented Dec 6, 2024

It might be possible to convert UniTask to Task using AsTask(), then use Task.WhenAll() to replace UniTask.WhenAll()

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

5 participants