-
Notifications
You must be signed in to change notification settings - Fork 275
Use ThrowIfCancellationRequested
instead of simply returning
#5343
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
base: main
Are you sure you want to change the base?
Conversation
Ping @nohwnd for review |
What is the benefit that this change brings? Is it to make sure that we are respecting the cancellation and don't get stuck in subsequent code that handles the return? Do you have some link to best practices that say why we should prefer one over the other? 🙂 |
For our current code, it's mostly identical. But using |
my 2c
In general the platform handle the cancelled outcome/return value...so user can use or not the token correctly and bug aside we will be always correct(cooperative means that user could not cooperate). |
I personally don't see a perf concern here. However, for our specific case (at least for the implementation that exists today, there is not much difference between returning vs throwing. So putting on hold for now. |
At least for testfx/src/Platform/Microsoft.Testing.Platform/Messages/ChannelConsumerDataProcessor.cs Line 57 in 5bd7584
then .NET will do this: So, when awaiting the canceled task, we will get a TaskCanceledException (derives from OperationCanceledException) and we will get to the catch anyways. For the rest of usages, I suspect that currently we may be doing more work due to not observing cancellation correctly. |
@nohwnd What do you think?
cc @Evangelink @MarcoRossignoli
Fixes #5063