Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

New rule proposal: Provide CancellationToken in calls #36

Open
sharwell opened this issue Sep 10, 2015 · 2 comments
Open

New rule proposal: Provide CancellationToken in calls #36

sharwell opened this issue Sep 10, 2015 · 2 comments

Comments

@sharwell
Copy link
Member

This diagnostic would be reported if a method M is called without providing a CancellationToken, and either M or one of its overloads has a CancellationToken parameter.

The code fix for this would attempt to fill in the CancellationToken as follows:

  1. If a local variable or parameter provides a CancellationToken (with consideration for context objects as described in New rule proposal: Async methods should have a CancellationToken parameter #32), the innermost visible CancellationToken is passed.
  2. Otherwise, pass CancellationToken.None.

⚠️ Separate equivalence keys should be used for the code fix for the case where the updated call still calls the same method, and the case where the updated call is to a different overload of the method.

@vweijsters
Copy link

👍

❓ How would this work with overloads, will this diagnostic effectively block overloads without a Cancellation token? If that is the case, this is too restrictive. I think calling an overload without a Cancellation should be allowed when there is no CancellationToken available is the scope

❓ How would a default parameter with value CancellationToken.None be handled when there is no other cancellation token available in the scope?

@sharwell
Copy link
Member Author

❓ How would this work with overloads, will this diagnostic effectively block overloads without a Cancellation token? If that is the case, this is too restrictive. I think calling an overload without a Cancellation should be allowed when there is no CancellationToken available is the scope

The problem with this is the reason no cancellation token is in scope could be that no one realized it was needed.

❓ How would a default parameter with value CancellationToken.None be handled when there is no other cancellation token available in the scope?

It would be reported as a warning by this diagnostic, and the code fix would treat the fixed code as calling the same method (see the note on equivalence keys in the original post above).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants