Skip to content

Commit 7567acc

Browse files
Extend snippet explanation
Extend explanation about how the state is captured. See #2290 (comment).
1 parent 607535c commit 7567acc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/advanced/performance.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ await resiliencePipeline.ExecuteAsync(
3737
cancellationToken);
3838

3939
// This approach uses a static lambda, avoiding allocations.
40-
// The "userId" is stored as state, and the lambda consumes it.
40+
// The "userId" is passed to the execution via the state argument, and the lambda consumes it as the first
41+
// parameter passed to the GetMemberAsync() method. In this case, userIdAsState and userId are the same value.
4142
await resiliencePipeline.ExecuteAsync(
42-
static (state, cancellationToken) => GetMemberAsync(state, cancellationToken),
43+
static (userIdAsState, cancellationToken) => GetMemberAsync(userIdAsState, cancellationToken),
4344
userId,
4445
cancellationToken);
4546
```

src/Snippets/Docs/Performance.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ await resiliencePipeline.ExecuteAsync(
2222
cancellationToken);
2323

2424
// This approach uses a static lambda, avoiding allocations.
25-
// The "userId" is stored as state, and the lambda consumes it.
25+
// The "userId" is passed to the execution via the state argument, and the lambda consumes it as the first
26+
// parameter passed to the GetMemberAsync() method. In this case, userIdAsState and userId are the same value.
2627
await resiliencePipeline.ExecuteAsync(
27-
static (state, cancellationToken) => GetMemberAsync(state, cancellationToken),
28+
static (userIdAsState, cancellationToken) => GetMemberAsync(userIdAsState, cancellationToken),
2829
userId,
2930
cancellationToken);
3031

0 commit comments

Comments
 (0)