Replies: 5 comments 15 replies
-
Maybe unirx can help you.
|
Beta Was this translation helpful? Give feedback.
-
Isn't this default C# behavior? My suggestion would be that if you want the other tasks to be canceled then you do indeed cancel the token. |
Beta Was this translation helpful? Give feedback.
-
any update on this? |
Beta Was this translation helpful? Give feedback.
-
So to actually cancel the remaining task(s) you'd have to create a new token source and cancel it afterwards, right? Something like this:
Does not seem overly verbose to me but maybe there's something I'm missing? |
Beta Was this translation helpful? Give feedback.
-
Just check if the cancellationToken.IsCancellationRequested and don't await then. Once you await cancelling the completion source will throw a Task Cancelled Exception at the await as intended
…On March 26, 2025 3:12:45 PM GMT+01:00, Meister der Magie ***@***.***> wrote:
Interesting approach, but I wonder how you pass a CancellationToken to the _completionSource.
Let's take the example of @Blackclaws but add a CancellationToken parameter:
´´´
async UniTask ShowScreen(CancellationToken cancellationToken) {
_completionSource.TrySetCanceled();
_completionSource = new();
/* Screen show logic here */
await _completionSource.Task; //How to stop the await if the passed cancellationToken was cancelled? I can't find a solution for this.
/* more work here */
}
´´´
--
Reply to this email directly or view it on GitHub:
#389 (reply in thread)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi, I've noticed that using WhenAny systematically creates leaked tasks:
When either event happens, the other task stays pending until the cancellationToken is triggered.
Creating a new merged cancellationToken for every case of WhenAny and canceling it afterward seems tedious and error-prone.
Is there a way to dissolve the tasks after the await?
Is there a simple pattern to deal with these cases gracefully?
Beta Was this translation helpful? Give feedback.
All reactions