Skip to content

Commit

Permalink
Fix pending tasks wait loop in (async) "Merge"
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Jan 20, 2024
1 parent 60390e8 commit 5bf0bbc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions MoreLinq/Experimental/Async/Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ async ValueTask<(bool, T)> ReadAsync(IAsyncEnumerator<T> enumerator)
// is in some defined state before disposing it otherwise it could throw
// "NotSupportedException".

if (pendingTaskList is { Count: > 0 })
if (pendingTaskList is { Count: > 0 } somePendingTaskList)
{
while (await Task.WhenAny(pendingTaskList)
.ConfigureAwait(false) is { } completedTask)
do
{
_ = pendingTaskList.Remove(completedTask);
var completedTask = await Task.WhenAny(somePendingTaskList).ConfigureAwait(false);
_ = somePendingTaskList.Remove(completedTask);
}
while (somePendingTaskList.Count > 0);
}

foreach (var enumerator in enumeratorList)
Expand Down

0 comments on commit 5bf0bbc

Please sign in to comment.