2023-05-19 03:14:23 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace YoutubeDownloader.Core.Utils.Extensions;
|
|
|
|
|
|
2023-07-12 17:22:13 +03:00
|
|
|
|
public static class AsyncCollectionExtensions
|
2023-05-19 03:14:23 +03:00
|
|
|
|
{
|
2023-05-22 10:08:16 +03:00
|
|
|
|
private static async ValueTask<IReadOnlyList<T>> CollectAsync<T>(
|
2023-10-21 17:58:59 +03:00
|
|
|
|
this IAsyncEnumerable<T> asyncEnumerable
|
|
|
|
|
)
|
2023-05-19 03:14:23 +03:00
|
|
|
|
{
|
|
|
|
|
var list = new List<T>();
|
|
|
|
|
|
|
|
|
|
await foreach (var i in asyncEnumerable)
|
|
|
|
|
list.Add(i);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ValueTaskAwaiter<IReadOnlyList<T>> GetAwaiter<T>(
|
2023-10-21 17:58:59 +03:00
|
|
|
|
this IAsyncEnumerable<T> asyncEnumerable
|
|
|
|
|
) => asyncEnumerable.CollectAsync().GetAwaiter();
|
|
|
|
|
}
|