Skip to content

Add optional CancellationToken support across the client API - #3079

Open
hughesjs wants to merge 8 commits into
octokit:mainfrom
hughesjs:worktree-cancellation-token-support
Open

Add optional CancellationToken support across the client API#3079
hughesjs wants to merge 8 commits into
octokit:mainfrom
hughesjs:worktree-cancellation-token-support

Conversation

@hughesjs

@hughesjs hughesjs commented Jun 18, 2026

Copy link
Copy Markdown

What

Adds an optional CancellationToken cancellationToken = default to the public client API across Octokit and Octokit.Reactive, threaded from the client methods down through ApiConnection/Connection to the HTTP layer (which already accepted a token). Follows the existing in-place precedent set by #2988 (OAuth client) rather than adding parallel overloads.

Implements the request in #1840. Also relevant to #744 (per-request timeouts) and #2956 (making timeouts/cancellation actually useful), since a caller-supplied CancellationToken enables per-request cancellation/timeout.

Scope

  • Foundation: IApiConnection/ApiConnection and the Reactive GetAndFlattenAllPages helpers now accept and forward the token.
  • Clients: every public Task/Task<T> method (and IObservable<T> method on the reactive clients) gained the trailing optional token, threaded into the underlying call.
  • AsyncPagination generator updated so generated extensions remain valid with the new optional parameter.
  • params-array methods are intentionally left unchanged (C# disallows a parameter after params).
  • Also fixes the concellationToken typo in IOAuthClient.

Compatibility

Source-compatible for callers (trailing optional parameter with a default). Existing behaviour is unchanged when no token is supplied.

Verification

  • Full solution builds (netstandard2.0 / net462 / net6.0), 0 errors.
  • Octokit.Tests: 4552 passed, 0 failed, 2 skipped.
  • Octokit.Tests.Conventions: 2827 passed, 0 failed.

hughesjs added 7 commits June 18, 2026 17:13
Add CancellationToken cancellationToken = default as trailing parameter
to all 7 GetAndFlattenAllPages* overloads in ConnectionExtensions.cs,
forwarding the token to the underlying connection.Get<List<T>> calls.

Update 45 reactive test files to use the new 4-arg Get<List<T>> form
(uri, dict, Arg.Any<string>(), Arg.Any<CancellationToken>()), and add
a new ConnectionExtensionsTests.cs to verify token propagation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 Triage

Development

Successfully merging this pull request may close these issues.

2 participants