Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
[API Proposal]: Add async overload of ChangeToken.OnChange #69099
Copy link
Copy link
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-Extensions-Primitivesbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.Issue or PR that represents a breaking API or functional change over a previous release.in-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedneeds-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnetBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet
Milestone
Description
Activity
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-Extensions-Primitivesbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.Issue or PR that represents a breaking API or functional change over a previous release.in-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is mergedneeds-breaking-change-doc-createdBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnetBreaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet
Background and motivation
Today it's not possible to use
ChangeToken.OnChangeto execute asynchronous logic before re-subscribing for new updates. The current API has anAction<T>based callback only. We need an async overload to run async logic so people don't end up using async void or blocking when using this helper.API Proposal
API Usage
Alternatives (added by @svick)
CancellationTokenparameter that's canceled when a following change is detected. This would probably be confusing, since not every caller would want to honor it and can be implemented by users if needed.OnAsyncChange(or similar). For those that useasynclambda withOnChangetoday, this would be less breaking, but they wouldn't automatically get the benefit of the new version.Risk (added by @svick)
This change means that existing code that uses an
asynclambda when callingOnChangewill change meaning: previously, it compiled to anasync voidmethod; with this change, it will be anasync Taskmethod, where the callback is re-registered only once the returnedTaskcompletes. This could break some users, though the new behavior should be more correct.