-
Notifications
You must be signed in to change notification settings - Fork 16
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 support for CancellationTokens within client and services methods. #33
Conversation
Classes now utilize the usage of <inheritdoc> to inherit the implemented interface documentation and reduce duplicate documentation comments.
The added interface inherits from ITodoistRestClient and extends it with method overloads that support cancellation. TodoistRestClient is also changed to implement ICancellableTodoistRestClient.
…lient. In TodoistClient we typically pass the cancellation token to _restClient if it implements ICancellableTodoistRestClient. The rest is just passing the cancellation token as a parameter along the method call chain.
…methods. Cancellation tokens are then passed to the IAdvancedTodoistClient method calls.
…RestClient argument.
One extra change has been committed: This change is not necessarily part of the proposed contribution, it's just a design change. It's up to you to include it in the merge if you accept the pull request. |
Thank you for the contibution 👍🏻 |
I'd choose breaking changes over introducing a new interface in this case. |
Ok, I will add a commit with these changes. |
And added cancellation tokens to ITodoistRestClient directly.
|
Kudos, SonarCloud Quality Gate passed!
|
This one is a little bigger than usual.
Since
HttpClient
supports optionalCancellationToken
in its methods,TodoistRestClient
can be changed to accept cancellation tokens and pass them toHttpClient
method calls.First, important things to consider:
TodoistRestClient
should not affect consumers of that class, so theCancellationToken
must be optional.ITodoistRestClient
interface would break classes that implement it, so the interface should remain unchanged.Based on those constraints, to accept the optional
CancellationToken
, anICancellableTodoistRestClient
interface is added that inherits fromITodoistRestClient
and extends it with method overloads that accept theCancellationToken
parameter.TodoistRestClient
is then changed to implementICancellableTodoistRestClient
and support cancellation.Second, cancellation tokens are like async methods; they are “contagious” all the way down the method call chain. This means in order to utilize the usage of cancellation tokens added to
TodoistRestClient
, thenTodoistClient
,TodoistTokenlessClient
, and all services that depend on them need to have optionalCancellationToken
parameter in their methods as well.Changes then were too many so they were split into four commits to become easy to review:
<inheritdoc>
tag so they change dynamically whenCancellationToken
parameters are added to interfaces.ICancellableTodoistRestClient
is added along with theTodoistRestClient
implementation for it.TodoistClient
is updated to support cancellation by checking if the_restClient
field implementsICancellableTodoistRestClient
and then passes theCancellationToken
to it.TodoistClient
are updated to accept cancellation tokens and pass them toTodoistClient
methods.I hope you find this contribution useful and not too hard to review.