Skip to content
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

Document that CancellationToken.None is default(CancellationToken) #14004

Closed
scalablecory opened this issue Jan 21, 2015 · 9 comments
Closed
Assignees
Labels
documentation Documentation bug or enhancement, does not impact product or test code
Milestone

Comments

@scalablecory
Copy link
Contributor

I feel that current practice of providing two overloads for cancellable async methods is overly verbose and leads to bloated APIs and error-prone implementation.

Task DoAsync()
Task DoAsync(CancellationToken token)

It would be much easier to use default parameters, for instance:

Task DoAsync(CancellationToken token = default(CancellationToken))

This currently works, but default(CancellationToken) being equivalent to CancellationToken.None is undocumented behavior (not mentioned in comments or MSDN) and thus not something we can 100% count on working in the future.

I'd like to propose the simple change of making this a documented feature.

@stephentoub
Copy link
Member

You can definitely count on this being the case; even if we wanted to change it (we don't), we wouldn't be able to as too much code depends on it. But your suggestion to improve the docs with the information is a good one.

@rpetrusha
Copy link

We'll update the documentation to note that default(CancellationToken) is equivalent to default(CancellationToken). The changes should appear in the next documentation update later this month.

Thanks for making this suggestion.

@stephentoub
Copy link
Member

Thanks, @rpetrusha.

@scalablecory
Copy link
Contributor Author

Thanks.

@stephentoub
Copy link
Member

Thanks for the suggestion.

Olafski referenced this issue in Olafski/corefx Jun 15, 2017
Add runtime info to dl archives
@ohadschn
Copy link

ohadschn commented Aug 22, 2017

I think the wording could be better.

The description says:

Returns an empty CancellationToken value.

The remarks section says:

You can also use the C# default(CancellationToken) statement to create an empty cancellation token.

So it's clear that both methods create empty cancellation tokens, but nothing defines exactly what an "empty" cancellation token means, and specifically it's not clear that two "empty" cancellation token are guaranteed to be equal.

@ohadschn
Copy link

@scalablecory If you agree with me, perhaps re-open this issue?

@svick
Copy link
Contributor

svick commented Nov 25, 2017

@ohadschn Issues in .Net documentation on docs.microsoft.com belong to the dotnet/docs repo, so I think you should create an issue there, instead of reopening it here. Or you could even submit a PR fixing it yourself.

@ohadschn
Copy link

@svick done: dotnet/docs#3787.

rpetrusha referenced this issue in dotnet/docs Nov 26, 2017
* Clarify that that two empty cancellation tokens are always equal

Addresses https://github.com/dotnet/corefx/issues/495#issuecomment-323999818

* CR fixes

Fixes comment: #3787 (review)
mairaw referenced this issue in mairaw/dotnet-api-docs-old Mar 29, 2018
mairaw referenced this issue in mairaw/dotnet-api-docs-old Mar 29, 2018
kzu referenced this issue in kzu/StyleCopAnalyzers Feb 7, 2019
Since `CancellationToken.None` is equivalent to `default(CancellationToken)`
according to https://github.com/dotnet/corefx/issues/495#issuecomment-72322134,
and since the latter can further be shortened to just `default`, make use of
both to cleanup a bunch of method calls that all ended up using just
`CancellationToken.None`.
kzu referenced this issue in kzu/StyleCopAnalyzers Feb 7, 2019
Since `CancellationToken.None` is equivalent to `default(CancellationToken)`
according to https://github.com/dotnet/corefx/issues/495#issuecomment-72322134,
and since the latter can further be shortened to just `default`, make use of
both to cleanup a bunch of method calls that all ended up using just
`CancellationToken.None`.
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation bug or enhancement, does not impact product or test code
Projects
None yet
Development

No branches or pull requests

6 participants