From ed5a3ebec98a8f77464443000d174badffc06fb7 Mon Sep 17 00:00:00 2001 From: Tim Cassell <35501420+timcassell@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:14:49 -0400 Subject: [PATCH] Added link to retry example in capture-values.md --- Docs/Guides/capture-values.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Docs/Guides/capture-values.md b/Docs/Guides/capture-values.md index a337f1f9..d5436195 100644 --- a/Docs/Guides/capture-values.md +++ b/Docs/Guides/capture-values.md @@ -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 Download(string url, int maxRetries = 0) @@ -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. \ No newline at end of file +See [Understanding Then](the-basics.md#understanding-then) for information on all the different ways you can capture values with the `Then` overloads.