From 7567acc330c9f74d6c7b14897a8ef4d15e9d475a Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 8 Nov 2024 15:38:42 +0000 Subject: [PATCH] Extend snippet explanation Extend explanation about how the state is captured. See https://github.com/App-vNext/Polly/pull/2290#issuecomment-2465027418. --- docs/advanced/performance.md | 5 +++-- src/Snippets/Docs/Performance.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/advanced/performance.md b/docs/advanced/performance.md index afa23240537..4c38e37b288 100644 --- a/docs/advanced/performance.md +++ b/docs/advanced/performance.md @@ -37,9 +37,10 @@ await resiliencePipeline.ExecuteAsync( cancellationToken); // This approach uses a static lambda, avoiding allocations. -// The "userId" is stored as state, and the lambda consumes it. +// The "userId" is passed to the execution via the state argument, and the lambda consumes it as the first +// parameter passed to the GetMemberAsync() method. In this case, userIdAsState and userId are the same value. await resiliencePipeline.ExecuteAsync( - static (state, cancellationToken) => GetMemberAsync(state, cancellationToken), + static (userIdAsState, cancellationToken) => GetMemberAsync(userIdAsState, cancellationToken), userId, cancellationToken); ``` diff --git a/src/Snippets/Docs/Performance.cs b/src/Snippets/Docs/Performance.cs index fb4bfc8cb9b..0af9d0881b9 100644 --- a/src/Snippets/Docs/Performance.cs +++ b/src/Snippets/Docs/Performance.cs @@ -22,9 +22,10 @@ await resiliencePipeline.ExecuteAsync( cancellationToken); // This approach uses a static lambda, avoiding allocations. - // The "userId" is stored as state, and the lambda consumes it. + // The "userId" is passed to the execution via the state argument, and the lambda consumes it as the first + // parameter passed to the GetMemberAsync() method. In this case, userIdAsState and userId are the same value. await resiliencePipeline.ExecuteAsync( - static (state, cancellationToken) => GetMemberAsync(state, cancellationToken), + static (userIdAsState, cancellationToken) => GetMemberAsync(userIdAsState, cancellationToken), userId, cancellationToken);