-
Notifications
You must be signed in to change notification settings - Fork 405
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
Add CancellationToken
Parameter to Methods Returning Task
and ValueTask
#1503
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ub.com/CommunityToolkit/Maui into Add-CancellationToken-to-Async-Methods
…ub.com/CommunityToolkit/Maui into Add-CancellationToken-to-Async-Methods
brminnick
added
pending documentation
This feature requires documentation
do not merge
Do not merge this PR
breaking change
This label is used for PRs that include a breaking change
labels
Nov 7, 2023
pictos
reviewed
Nov 8, 2023
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.
This is a great idea! I've two comments around the current implementation
src/CommunityToolkit.Maui.Core/Views/DrawingView/Service/DrawingViewService.macios.cs
Outdated
Show resolved
Hide resolved
@pictos Ok! This PR is ready for Review (again!).
I've removed the
do not merge
|
src/CommunityToolkit.Maui.Core/Essentials/SpeechToText/SpeechToTextImplementation.windows.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.Core/Views/DrawingView/Service/DrawingViewService.android.cs
Show resolved
Hide resolved
brminnick
commented
Nov 9, 2023
brminnick
commented
Nov 9, 2023
VladislavAntonyuk
approved these changes
Nov 10, 2023
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
This PR updates every method that returns a
Task
orValueTask
to include aCancellationToken
as a parameter.This ensures that the .NET MAUI Community Toolkit follows Microsoft's recommended async/await Best Practices to always support Task Cancellation.
Requiring a
CancellationToken
also ensures that analyzerCA2016
("Forward the 'cancellationToken' parameter methods that take one") correctly alerts developers using our library to propagate theirCancellationToken
to our APIs.I've also removed the default values forCancellationToken
parameters (egCancellationToken token = default
->CancellationToken token
) . This follows the best-practice recommendation for Libraries to require the developer to make a thoughtful choice as to how to handle cancellation.Update: Looking at the .NET BCL, their APIs provide default values for
CancellationToken
. Therefore, we too will provide default values for ourCancellationToken
parameters (egCancellation token = default)
).Example:
IDrawingView.GetImageStream
For example, the
IDrawingView.GetImageStream
method changes frombecomes
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRCancellationToken
Parameter to Methods ReturningTask
andValueTask
MicrosoftDocs/CommunityToolkit#335Additional information
In the
.editorconfig
, I've promotedCA1068
toerror
to ensure that we follow best-practices when adding aCancellationToken
as a parameter to methods.I've added the breaking changeThis label is used for PRs that include a breaking change
label because this modifies existing APIs. I recommend merging this before we publish
CommunityToolkit v7.0.0
which contains the existing breaking change targeting .NET 8.This PR also adds a
Timeout
to every Unit Test that returns aTask
to ensure our Unit Test timeout when a deadlock is encountered.I've also added do not mergeDo not merge this PR
label until Unit Tests are added and Documentation is updated.