Added async overload of ChangeToken.OnChange#129624
Draft
svick wants to merge 4 commits into
Draft
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-primitives |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends Microsoft.Extensions.Primitives.ChangeToken with Task-returning OnChange overloads so consumers can run asynchronous work and delay re-registration until that work completes, and it refactors the internal registration logic to share more between sync and async paths.
Changes:
- Add
ChangeToken.OnChange(Func<IChangeToken?>, Func<Task>)andChangeToken.OnChange<TState>(Func<IChangeToken?>, Func<TState, Task>, TState)public overloads. - Refactor registration implementation into shared base + sync/async derived registrations.
- Update/add unit tests covering async behavior, disposal while in-flight, and overload binding.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/Microsoft.Extensions.Primitives/src/ChangeToken.cs | Adds async overloads and refactors internal registration to support deferred re-registration after Task completion. |
| src/libraries/Microsoft.Extensions.Primitives/ref/Microsoft.Extensions.Primitives.cs | Updates ref assembly to include the new public overloads. |
| src/libraries/Microsoft.Extensions.Primitives/tests/ChangeTokenTest.cs | Adjusts existing tests for overload binding and adds new tests for async/disposal/coalescing semantics. |
Comment on lines
+272
to
+283
| private async Task AwaitConsumerAndRegisterCallback(Task consumerTask, IChangeToken? token) | ||
| { | ||
| try | ||
| { | ||
| await consumerTask.ConfigureAwait(false); | ||
| } | ||
| finally | ||
| { | ||
| // We always want to ensure the callback is registered | ||
| RegisterChangeTokenCallback(token); | ||
| } | ||
| } |
Comment on lines
+70
to
+74
| /// <remarks> | ||
| /// Exceptions from <paramref name="changeTokenProducer"/> are propagated to the caller of this method or to the code that triggers the change token. | ||
| /// Synchronous exceptions from <paramref name="changeTokenConsumer"/> are propagated to the code that triggers the change token. | ||
| /// Asynchronous exceptions from <paramref name="changeTokenConsumer"/> are left unobserved. | ||
| /// </remarks> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.