diff --git a/src/HotChocolate/Core/src/Execution/RequestExecutor.cs b/src/HotChocolate/Core/src/Execution/RequestExecutor.cs index 00c9098c3eb..1172f15bfe0 100644 --- a/src/HotChocolate/Core/src/Execution/RequestExecutor.cs +++ b/src/HotChocolate/Core/src/Execution/RequestExecutor.cs @@ -241,47 +241,30 @@ private async IAsyncEnumerable ExecuteBatchStream( } var buffer = new IOperationResult[8]; - int bufferCount; do { - bufferCount = completed.TryPopRange(buffer); + var resultCount = completed.TryPopRange(buffer); - for (var i = 0; i < bufferCount; i++) + for (var i = 0; i < resultCount; i++) { yield return buffer[i]; } - if (bufferCount == 0) + if (completed.IsEmpty && tasks.Count > 0) { - if(tasks.Any(t => !t.IsCompleted)) - { - var task = await Task.WhenAny(tasks); + var task = await Task.WhenAny(tasks); - if (task.Status is not TaskStatus.RanToCompletion) - { - // we await to throw if it's not successful. - await task; - } - - tasks.Remove(task); - } - else + // we await to throw if it's not successful. + if (task.Status is not TaskStatus.RanToCompletion) { - foreach (var task in tasks) - { - if (task.Status is not TaskStatus.RanToCompletion) - { - // we await to throw if it's not successful. - await task; - } - } - - tasks.Clear(); + await task; } + + tasks.Remove(task); } } - while (tasks.Count > 0 || bufferCount > 0); + while (tasks.Count > 0 || !completed.IsEmpty); } private static IOperationRequest WithServices(IOperationRequest request, IServiceProvider services)