mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-10-04 02:11:11 +00:00
Added WaitAllAsync extension method
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
@@ -625,7 +626,6 @@ namespace CryptoExchange.Net.SharedApis
|
||||
.ParallelEnumerateAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to trade updates for all capabilities in parallel and return results as they arrive
|
||||
/// </summary>
|
||||
@@ -807,5 +807,17 @@ namespace CryptoExchange.Net.SharedApis
|
||||
.Select(x => x.Capability.SubscribeToUserTradeUpdatesAsync(request, onData, ct))
|
||||
.ParallelEnumerateAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for all results from an IAsyncEnumerable and return them as an array
|
||||
/// </summary>
|
||||
public static async Task<T[]> WaitAllAsync<T>(this IAsyncEnumerable<T> enumerable)
|
||||
{
|
||||
var result = new List<T>();
|
||||
await foreach (var itemResult in enumerable.ConfigureAwait(false))
|
||||
result.Add(itemResult);
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user