Skip to content

Avoid capturing where possible.#1609

Merged
martintmk merged 2 commits intoApp-vNext:mainfrom
IEvangelist:avoid-capturing-context
Sep 22, 2023
Merged

Avoid capturing where possible.#1609
martintmk merged 2 commits intoApp-vNext:mainfrom
IEvangelist:avoid-capturing-context

Conversation

@IEvangelist
Copy link
Contributor

The issue or feature being addressed

All of these changes are only within the Docs/Snippets content.

When reviewing docs, I noticed that some of the example snippets were lifting (capturing outer scope variables) when it clearly wasn't intended as the state parameter was passed an argument with the same name. Ideally, we shouldn't be capturing outer scope variables when using the state parameter.

Details on the issue fix or feature implementation

In this PR:

  • Some cases are simply resolved by adding the static modifier.
  • Other cases involved renaming the delegate parameter for the inner scope to isolate the variable usage.
  • And a few cases required passing state.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

Copy link
Contributor

@martintmk martintmk left a comment

Choose a reason for hiding this comment

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

Please also run dotnet mdsnippets from the Polly root to update the relevant docs.

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (8241fc4) 84.63% compared to head (bfe49e4) 84.63%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1609   +/-   ##
=======================================
  Coverage   84.63%   84.63%           
=======================================
  Files         306      306           
  Lines        6820     6820           
  Branches     1044     1044           
=======================================
  Hits         5772     5772           
  Misses        839      839           
  Partials      209      209           
Flag Coverage Δ
linux 84.63% <ø> (ø)
macos 84.63% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@martintmk martintmk enabled auto-merge (squash) September 21, 2023 18:31
@martintmk martintmk merged commit a01e9c0 into App-vNext:main Sep 22, 2023
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.

2 participants