-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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 TaskCompletionSource.SetCanceled(CancellationToken) #30862
Labels
Milestone
Comments
CC @stephentoub |
This is reasonable. |
terrajobst
added
api-approved
API was approved in API review, it can be implemented
and removed
api-ready-for-review
labels
Feb 20, 2020
public class TaskCompletionSource<TResult>
{
...
public void SetCanceled(CancellationToken cancellationToken);
...
} |
Frassle
added a commit
to Frassle/runtime
that referenced
this issue
Feb 22, 2020
maryamariyan
added
the
untriaged
New issue has not been triaged by the area owner
label
Feb 23, 2020
stephentoub
pushed a commit
that referenced
this issue
Feb 25, 2020
* Add TaskCompletionSource.SetCanceled(CancellationToken) api-approved by #30862 * Add to ref * SetCanceled(default) * Change some tests to use SetCaneled not TrySetCanceled These tests used SetResult/SetException and TrySetCancelled so it could pass a token. Changed to use SetCancelled to match the Result/Exception useage. * Add SetCanceled(CT) test * Check exception on re-cancel * Equal not Equals * Catch aggregate not TaskCancelled directly * Inner not exc * Markup * s/m/n
Fixed by #32696 |
stephentoub
removed
the
untriaged
New issue has not been triaged by the area owner
label
Feb 25, 2020
ghost
locked as resolved and limited conversation to collaborators
Dec 12, 2020
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
TaskCompletionSource
currently has three methods to set it to canceled.void SetCanceled()
which throws if the source is already completed,bool TrySetCanceled()
which just returns false if the source is already cancelled, andbool TrySetCanceled(CancellationToken)
which is likeTrySetCanceled
but also allows linking in aCancellationToken
.Can we also add
void SetCanceled(CancellationToken)
to use in cases where you want to make it clear that this should set the canceled state but you also want to link aCancellationToken
in.This is doable by writing your own that just throws if
TrySetCanceled
returns false but this can't easily get theTaskT_TransitionToFinal_AlreadyCompleted
resource string to match the error message thrown by corefx. It also leads to people just writingTrySetCanceled
and ignoring the result, which leads to less clear code and potentially hides bugs, or alternatively they writeSetCanceled
and throw away the token information (Me trying to fix one case of this in FSharp.Core is what lead to me raising this issue).The text was updated successfully, but these errors were encountered: