Skip to content

Instantly share code, notes, and snippets.

View KirillShlenskiy's full-sized avatar

Kirill Shlenskiy KirillShlenskiy

  • Canberra, Australia
View GitHub Profile
/// <summary>
/// Executes the given async delegates in parallel,
/// up to the given maximum degree of parallelism.
/// </summary>
public static async Task InvokeAsync(IEnumerable<Func<Task>> taskFactories, int maxDegreeOfParallelism)
{
if (taskFactories == null) throw new ArgumentNullException(nameof(taskFactories));
if (maxDegreeOfParallelism <= 0) throw new ArgumentException(nameof(maxDegreeOfParallelism));
// Defensive copy. Similar to what Task.WhenAll/WhenAny does.