How to cancel UniTask.WhenAll()

Hello,

I have a List of tasks and I use “await UniTask.WhenAll(TaskList);” to wait for them to finish before advancing.
Recently I got necessity to prematurely cancel these tasks and advance early.
Unfortunately I cannot figure out how to do it.

It has something to do with CancellationTokenSource but I cannot understand how to use it with WhenAll.

One constraint is - I cannot use thread pool since that one is not supported by WebGL.

Thank you,
Alex.

Maybe you can try :

UniTask.WhenAll(TaskList)
.AttachExternalCancellation(cancellationToken);
3 Likes

Whoa! You’re awesome!
It works perfectly!

2 Likes

Nice, I’m glad to help you.:wink: Mark this as resolved if it worked

2 Likes