Skip to content

Commit

Permalink
Simplified running parallel tasks on the taskpool
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkendk committed Jun 4, 2018
1 parent 5bf0afa commit cb096fd
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/CoCoL/TaskPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,33 @@ public static async Task RunParallelAsync<T>(IEnumerable<T> tasks, Func<T, Task>
}
}

/// <summary>
/// Runs a repeated parallel operation with a maximum of 10 concurrent handlers
/// </summary>
/// <returns>An awaitable task.</returns>
/// <param name="source">The channel where requests are read from</param>
/// <param name="handler">The method to invoke for each item</param>
/// <param name="errorHandler">The error handler</param>
/// <typeparam name="T">The type of data elements to handle</typeparam>
public static Task RunParallelAsync<T>(IReadChannel<T> source, Func<T, Task> handler, Func<T, Exception, Task> errorHandler = null)
{
return RunParallelAsync(source, handler, default(System.Threading.CancellationToken), 10, errorHandler);
}

/// <summary>
/// Runs a repeated parallel operation
/// </summary>
/// <returns>An awaitable task.</returns>
/// <param name="source">The channel where requests are read from</param>
/// <param name="handler">The method to invoke for each item</param>
/// <param name="maxparallel">The maximum parallelism to use.</param>
/// <param name="errorHandler">The error handler</param>
/// <typeparam name="T">The type of data elements to handle</typeparam>
public static Task RunParallelAsync<T>(IReadChannel<T> source, Func<T, Task> handler, int maxparallel, Func<T, Exception, Task> errorHandler = null)
{
return RunParallelAsync(source, handler, default(System.Threading.CancellationToken), maxparallel, errorHandler);
}

/// <summary>
/// Runs a repeated parallel operation
/// </summary>
Expand All @@ -137,7 +164,7 @@ public static async Task RunParallelAsync<T>(IEnumerable<T> tasks, Func<T, Task>
/// <param name="maxparallel">The maximum parallelism to use.</param>
/// <param name="errorHandler">The error handler</param>
/// <typeparam name="T">The type of data elements to handle</typeparam>
public static Task RunParallelAsync<T>(IReadChannel<T> source, Func<T, Task> handler, System.Threading.CancellationToken token = default(System.Threading.CancellationToken), int maxparallel = 10, Func<T, Exception, Task> errorHandler = null)
public static Task RunParallelAsync<T>(IReadChannel<T> source, Func<T, Task> handler, System.Threading.CancellationToken token, int maxparallel = 10, Func<T, Exception, Task> errorHandler = null)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
Expand Down

0 comments on commit cb096fd

Please sign in to comment.