Skip to content

Cancellation Tokens on Async Methods#3449

Open
Narnian12 wants to merge 2 commits intoFirelyTeam:developfrom
Narnian12:develop
Open

Cancellation Tokens on Async Methods#3449
Narnian12 wants to merge 2 commits intoFirelyTeam:developfrom
Narnian12:develop

Conversation

@Narnian12
Copy link
Copy Markdown
Contributor

@Narnian12 Narnian12 commented Feb 24, 2026

Description

  • Optional cancellation tokens added to IAsyncResourceResolver async methods
    • Assigned to CancellationToken.None (default) by default
    • Propagates through all implementations
    • Most implementations accept it for API consistency, but do not use it
  • Implemented async version of CommonWebResolver.TryResolveByUriAsync()
    • Only call that honors cancellation token by ultimately sending it to HttpClient.SendAsync()

Related issues

Resolves #3081.

Testing

  • Added tests covering cancellation behavior on MultiResolver and WebResolver - wrapping CommonWebResolver with the async method honoring the token

FirelyTeam Checklist

  • Update the title of the PR to be succinct and less than 50 characters
  • Mark the PR with the label breaking change when this PR introduces breaking changes

@Narnian12 Narnian12 marked this pull request as draft February 25, 2026 03:51
@Narnian12
Copy link
Copy Markdown
Contributor Author

I think this needs the breaking change label added. I am unable to add it - can someone else add that label to this PR?

@alexzautke alexzautke added the breaking change This issue/commit causes a breaking change, and requires a major version upgrade label Feb 25, 2026
@Narnian12 Narnian12 marked this pull request as ready for review February 26, 2026 16:38
@mmsmits mmsmits requested review from a team and Kasdejong and removed request for a team and Kasdejong March 12, 2026 12:02
Copy link
Copy Markdown
Member

@ewoutkramer ewoutkramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one (minor) question about code duplication...

///<inheritdoc/>
public ResolverResult TryResolveByUri(string uri)
{
if (uri == null) throw Error.ArgumentNull(nameof(uri));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we implement this by calling the async version and blocking on it? I am trying to avoid the code duplication here....

@ewoutkramer
Copy link
Copy Markdown
Member

ewoutkramer commented Mar 12, 2026

About the breaking change....

I thought we could just add an optional param to the interface, but we cannot as existing clients would still break. But we can use default implementations:

interface X
{
	// New signature
	int Calculate(int a, int b, CancellationToken ct) =>
		Calculate(a,b);
	
	// Existing signature
	int Calculate(int a, int b);
}

We cannot do a breaking change until SDK7, which is probably almost 2 years out....

@Narnian12
Copy link
Copy Markdown
Contributor Author

About the breaking change....

I thought we could just add an optional param to the interface, but we cannot as existing clients would still break. But we can use default implementations:

interface X
{
	// New signature
	int Calculate(int a, int b, CancellationToken ct) =>
		Calculate(a,b);
	
	// Existing signature
	int Calculate(int a, int b);
}

We cannot do a breaking change until SDK7, which is probably almost 2 years out....

That makes sense, thanks! I can abandon this PR and make another one that overloads the original methods, so we don't have breaking changes. Or if there are more pressing issues to contend with, I can take a look at those as well.

@andrzejskowronski
Copy link
Copy Markdown
Contributor

andrzejskowronski commented Mar 24, 2026

I think it's fine to continue here, you'll just need to restore the original interface method and use default implementation for the new one that calls the original - and maybe some adjustments to implementers if necessary, maybe not :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This issue/commit causes a breaking change, and requires a major version upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

We need to add cancellationtokens to our async APIs

4 participants