Skip to content

Commit

Permalink
Added link to retry example in capture-values.md
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell authored Apr 2, 2024
1 parent 856d896 commit ed5a3eb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Docs/Guides/capture-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The C# compiler allows capturing variables inside delegates, known as closures. This involves creating a new object and a new delegate for every closure. These objects will eventually need to be garbage collected when the delegate is no longer reachable.

To solve this issue, capture values was added to the library. Every method that accepts a delegate can optionally take any value as a parameter, and pass that value as the first argument to the delegate. To capture multiple values, you should pass a `System.ValueTuple<>` that contains the values you wish to capture. The error retry example can be rewritten to reduce allocations:
To solve this issue, capture values was added to the library. Every method that accepts a delegate can optionally take any value as a parameter, and pass that value as the first argument to the delegate. To capture multiple values, you should pass a `System.ValueTuple<>` that contains the values you wish to capture. The [error retry example](retries-recursion.md) can be rewritten to reduce allocations:

```cs
public Promise<string> Download(string url, int maxRetries = 0)
Expand All @@ -25,4 +25,4 @@ When the C# compiler sees a lambda expression that does not capture/close any va

Note: Visual Studio will tell you what variables are captured/closed if you hover the `=>`. You can use that information to optimize your delegates. In C# 9 and later, you can use the `static` modifier on your lambdas so that the compiler will not let you accidentally capture variables the expensive way.

See [Understanding Then](the-basics.md#understanding-then) for information on all the different ways you can capture values with the `Then` overloads.
See [Understanding Then](the-basics.md#understanding-then) for information on all the different ways you can capture values with the `Then` overloads.

0 comments on commit ed5a3eb

Please sign in to comment.