Skip to content

Commit b70e7d6

Browse files
authored
Fix Closure Capture (#9429)
1 parent b263731 commit b70e7d6

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/HotChocolate/Fusion/src/Fusion.Execution/Execution/OperationPlanExecutor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public async Task<IExecutionResult> SubscribeAsync(
7676
var subscriptionResult = await subscriptionNode.SubscribeAsync(context, executionCts.Token);
7777
var executionState = context.ExecutionState;
7878

79-
cancellationRegistration = executionCts.Token.Register(() => executionState.Signal.TryResetToIdle());
79+
cancellationRegistration = executionCts.Token.Register(
80+
static state => Unsafe.As<AsyncAutoResetEvent>(state)!.TryResetToIdle(),
81+
executionState.Signal);
8082

8183
if (subscriptionResult.Status is not ExecutionStatus.Success)
8284
{
@@ -120,8 +122,9 @@ private static async Task ExecuteQueryAsync(
120122
{
121123
var executionState = context.ExecutionState;
122124

123-
await using var cancellationRegistration =
124-
cancellationToken.Register(() => executionState.Signal.TryResetToIdle());
125+
await using var cancellationRegistration = cancellationToken.Register(
126+
static state => Unsafe.As<AsyncAutoResetEvent>(state)!.TryResetToIdle(),
127+
executionState.Signal);
125128

126129
// GraphQL queries allow us to execute the plan by using full parallelism.
127130
// We fill the backlog with all nodes from the operation plan.
@@ -166,8 +169,9 @@ private static async Task ExecuteMutationAsync(
166169
{
167170
var executionState = context.ExecutionState;
168171

169-
await using var cancellationRegistration =
170-
cancellationToken.Register(() => executionState.Signal.TryResetToIdle());
172+
await using var cancellationRegistration = cancellationToken.Register(
173+
static state => Unsafe.As<AsyncAutoResetEvent>(state)!.TryResetToIdle(),
174+
executionState.Signal);
171175

172176
// For mutations, we fill the backlog with all nodes from the operation plan just like for queries.
173177
executionState.FillBacklog(plan);
@@ -228,7 +232,8 @@ private static async IAsyncEnumerable<OperationResult> CreateSubscriptionEnumera
228232
var stream = subscriptionResult.ReadStreamAsync()
229233
.WithCancellation(executionCancellationToken);
230234
await using var cancellationRegistration = executionCancellationToken.Register(
231-
() => executionState.Signal.TryResetToIdle());
235+
static state => Unsafe.As<AsyncAutoResetEvent>(state)!.TryResetToIdle(),
236+
executionState.Signal);
232237

233238
await foreach (var eventArgs in stream)
234239
{

0 commit comments

Comments
 (0)