Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: add cancellation tokens #184

Conversation

austindrenski
Copy link
Member

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1a14f6c) 0.00% compared to head (0dc319f) 94.73%.

❗ Current head 0dc319f differs from pull request most recent head b7b770a. Consider uploading reports for the commit b7b770a to get more accurate results

Additional details and impacted files
@@            Coverage Diff            @@
##           main     #184       +/-   ##
=========================================
+ Coverage      0   94.73%   +94.73%     
=========================================
  Files         0       23       +23     
  Lines         0      931      +931     
  Branches      0       93       +93     
=========================================
+ Hits          0      882      +882     
- Misses        0       29       +29     
- Partials      0       20       +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Austin Drenski <austin@austindrenski.io>
Copy link
Member

@benjiro benjiro left a comment

Choose a reason for hiding this comment

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

I'm fine with this, probably my bad for missing putting the CTs in the first place. Thanks for fixing it up, makes sense to support this specially if the library is being consumed in a web app.

Async suffix is a well understood convention and mentioned many times in the originally docs. I'm good with adding it, breaking change is minimal.

Nice work

@toddbaert toddbaert self-requested a review February 20, 2024 21:16
Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

I definitely want to do this, but I want to collect a few breaking changes and create an issue for them all... then we can perhaps maintain a v2 branch for a while, and merge it all at once when we're ready to release.

I'll create that issue to discuss, but blocking for now. Let me know if you disagree.

@toddbaert toddbaert added this to the 2.0 (breaking) milestone Feb 21, 2024
@kinyoklion
Copy link
Member

We should maybe update the conventional commit tag to have an exclamation point. Makes it easy to see that it needs to be held off.

@toddbaert toddbaert changed the title refactor: Cleanup + plumb cancellation tokens feat!: add cancellation tokens Apr 10, 2024
@toddbaert
Copy link
Member

I'm assigning this to myself. Next week I'll work on cleaning it up, which will hopefully also help me understand how we can best use these tokens in terms of how they integrate with the rest of the SDK's semantics.

We should maybe update the conventional commit tag to have an exclamation point. Makes it easy to see that it needs to be held off.

Did this, thanks @kinyoklion

@toddbaert toddbaert self-assigned this Apr 11, 2024
@toddbaert
Copy link
Member

I've started on this and #185

@toddbaert
Copy link
Member

Closing and continuing with #268

@toddbaert toddbaert closed this May 1, 2024
toddbaert added a commit that referenced this pull request Jun 17, 2024
This PR is a combination of
#184 and
#185. Changes include:

- adding cancellation tokens
- in all cases where async operations include side-effects
(`setProviderAsync`, `InitializeAsync`, I've specified in the in-line
doc that the cancellation token's purpose is to cancel such side-effects
- so setting a provider and canceling that operation still results in
that provider's being set, but async side-effect should be cancelled.
I'm interested in feedback here, I think we need to consider the
semantics around this... I suppose the alternative would be to always
ensure any state changes only occur after async side-effects, if they
weren't cancelled beforehand.
- adding "Async" suffix to all async methods
- remove deprecated sync `SetProvider` methods 
- Using `ValueTask` for hook methods
- I've decided against converting all `Tasks` to `ValueTasks`, from the
[official .NET
docs](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.valuetask?view=net-8.0):
> the default choice for any asynchronous method that does not return a
result should be to return a
[Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-8.0).
Only if performance analysis proves it worthwhile should a ValueTask be
used instead of a
[Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-8.0).
- I think for hooks, `ValueTask` especially makes sense since often
hooks are synchronous, in fact async hooks are probably the less likely
variant.
- I've kept the resolver methods as `Task`, but there could be an
argument for making them `ValueTask`, since some providers resolve
asynchronously.
- I'm still a bit dubious on the entire idea of `ValueTask`, so I'm
really interested in feedback here
- associated test updates

UPDATE:

After chewing on this for a night, I'm starting to feel:
- We should simply remove cancellation tokens from Init/Shutdown. We can
always add them later, which would be non-breaking. I think the value is
low and the complexity is potentially high.
- ValueTask is only a good idea for hooks, because:
  - Hooks will very often be synchronous under the hood
- We (SDK authors) await the hooks, not consumer code, so we can be
careful of the potential pitfalls of ValueTask. I think everywhere else
we should stick to Task.

---------

Signed-off-by: Austin Drenski <austin@austindrenski.io>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Co-authored-by: Austin Drenski <austin@austindrenski.io>
Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
Co-authored-by: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants