fix: add cancellation token support#34
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for cancellation tokens across all API methods, upgrades both client and test projects to .NET 9, and bumps related dependencies.
- Extend interface and implementation to pass
CancellationTokenthrough all requests - Upgrade target frameworks and package references in test and library projects
- Clean up Copilot-generated method signatures and overloads
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj | Bumped test project to net9.0 and updated package versions |
| src/AnthropicClient/IAnthropicApiClient.cs | Added optional CancellationToken to all API method signatures and XML docs |
| src/AnthropicClient/AnthropicClient.csproj | Updated Microsoft.Bcl.AsyncInterfaces and System.Text.Json package versions |
| src/AnthropicClient/AnthropicApiClient.cs | Propagated cancellation tokens into SendRequestAsync and method overloads |
Comments suppressed due to low confidence (4)
src/AnthropicClient/AnthropicApiClient.cs:305
- The
ReadResultsAsync()call does not receive the outercancellationToken, so cancellation won’t propagate into the result stream. Pass the token:ReadResultsAsync(cancellationToken).
return AnthropicResult<IAsyncEnumerable<MessageBatchResultItem>>.Success(ReadResultsAsync(), anthropicHeaders);
src/AnthropicClient/IAnthropicApiClient.cs:99
- The summary for
ListAllModelsAsyncis identical toListModelsAsync. Update it to something likeLists all models asynchronouslyto clarify its behavior.
/// <summary>Lists the models asynchronously</summary>
tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj:1
- [nitpick] New cancellation support should be covered by unit tests. Consider adding tests that assert cancellation requests properly abort ongoing operations for at least one API method.
<Project Sdk="Microsoft.NET.Sdk">
src/AnthropicClient/AnthropicApiClient.cs:306
- [nitpick] The inner generator parameter is named
ct, but other methods usecancellationToken. RenamecttocancellationTokenfor consistency and readability.
async IAsyncEnumerable<MessageBatchResultItem> ReadResultsAsync([EnumeratorCancellation] CancellationToken ct = default)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #34 +/- ##
==========================================
- Coverage 98.98% 98.85% -0.14%
==========================================
Files 81 81
Lines 1478 1479 +1
Branches 126 127 +1
==========================================
- Hits 1463 1462 -1
Misses 5 5
- Partials 10 12 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds CancellationToken support across the API surface and upgrades to .NET 9, including test and CI dependencies.
- Introduces optional
CancellationTokenparameters to all client methods - Updates project SDKs and package references to .NET 9
- Updates CI workflows and editor settings for .NET 9 compatibility
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj | Upgraded test project to net9.0 and bumped test dependencies |
| src/AnthropicClient/IAnthropicApiClient.cs | Added CancellationToken overloads and updated XML docs |
| src/AnthropicClient/AnthropicClient.csproj | Bumped library dependencies to versions compatible with .NET 9 |
| src/AnthropicClient/AnthropicApiClient.cs | Wired CancellationToken through all HTTP calls |
| .vscode/settings.json | Added new vocabulary for .NET 9 tooling |
| .github/workflows/pull_request.yml | Switched CI to use .NET 9 SDK |
| .github/workflows/publish.yml | Switched publish pipeline to use .NET 9 SDK |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
closes #33