Skip to content

Commit

Permalink
Remove dependency on System.Linq.Async
Browse files Browse the repository at this point in the history
Added ToListAsync implementation to eliminate dependency on
System.Linq.Async, which provided System.Linq.AsyncEnumerable.ToListAsync.

System.Linq.Async introduces extension methods to a default (or even
mandatory) namespace which conflict with other implementations, see:
dotnet/reactive#1057
  • Loading branch information
jcracknell committed Mar 10, 2022
1 parent 3f13132 commit c394f37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
<PackageReference Include="AsyncFixer" Version="1.1.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -74,4 +73,4 @@
-->
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public static class AsyncEnumerableExtensions
{
/// <summary>
/// Asynchronously materializes the subject <see cref="IAsyncEnumerable{T}"/> into a list.
/// </summary>
public static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken = default)
{
var list = new List<T>();
await foreach (var element in enumerable.WithCancellation(cancellationToken))
{
list.Add(element);
}

return list;
}
}

0 comments on commit c394f37

Please sign in to comment.