-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Comments
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. |
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. |
Thanks, @rpetrusha. |
Thanks. |
Thanks for the suggestion. |
I think the wording could be better. The description says:
The remarks section says:
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. |
@scalablecory If you agree with me, perhaps re-open this issue? |
@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. |
@svick done: dotnet/docs#3787. |
* 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)
* Clarify that that two empty cancellation tokens are always equal Addresses https://github.com/dotnet/corefx/issues/495#issuecomment-323999818 * CR fixes Fixes comment: dotnet/docs#3787 (review)
* Clarify that that two empty cancellation tokens are always equal Addresses https://github.com/dotnet/corefx/issues/495#issuecomment-323999818 * CR fixes Fixes comment: dotnet/docs#3787 (review)
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`.
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`.
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 toCancellationToken.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.
The text was updated successfully, but these errors were encountered: