Skip to content

Commit

Permalink
Extend snippet explanation
Browse files Browse the repository at this point in the history
Extend explanation about how the state is captured.
See #2290 (comment).
  • Loading branch information
martincostello committed Nov 11, 2024
1 parent 607535c commit 7567acc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions docs/advanced/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
Expand Down
5 changes: 3 additions & 2 deletions src/Snippets/Docs/Performance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7567acc

Please sign in to comment.