77
88namespace CSRakowski . Parallel
99{
10- #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_0_OR_GREATER
11-
1210 public static partial class ParallelAsync
1311 {
1412 #region IEnumerable<T>
@@ -41,12 +39,16 @@ public static partial class ParallelAsync
4139 /// Setting this value to low, will mean a too small list will be allocated and you will have to pay a small performance hit for the resizing of the list during execution.
4240 /// </para>
4341 /// </remarks>
44- public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IEnumerable < TIn > collection , Func < TIn , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
42+ public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IEnumerable < TIn > collection , Func < TIn , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , CancellationToken cancellationToken = default )
4543 {
44+ #if NET8_0_OR_GREATER
45+ ArgumentNullException . ThrowIfNull ( func ) ;
46+ #else
4647 if ( func == null )
4748 {
4849 throw new ArgumentNullException ( nameof ( func ) ) ;
4950 }
51+ #endif //NET8_0_OR_GREATER
5052
5153 var funcWithCancellationToken = WrapFunc ( func ) ;
5254 return ForEachAsyncStream < TResult , TIn > ( collection , funcWithCancellationToken , maxBatchSize , allowOutOfOrderProcessing , estimatedResultSize , cancellationToken ) ;
@@ -80,8 +82,12 @@ public static IAsyncEnumerable<TResult> ForEachAsyncStream<TResult, TIn>(IEnumer
8082 /// Setting this value to low, will mean a too small list will be allocated and you will have to pay a small performance hit for the resizing of the list during execution.
8183 /// </para>
8284 /// </remarks>
83- public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IEnumerable < TIn > collection , Func < TIn , CancellationToken , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
85+ public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IEnumerable < TIn > collection , Func < TIn , CancellationToken , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , CancellationToken cancellationToken = default )
8486 {
87+ #if NET8_0_OR_GREATER
88+ ArgumentNullException . ThrowIfNull ( collection ) ;
89+ ArgumentNullException . ThrowIfNull ( func ) ;
90+ #else
8591 if ( collection == null )
8692 {
8793 throw new ArgumentNullException ( nameof ( collection ) ) ;
@@ -91,6 +97,7 @@ public static IAsyncEnumerable<TResult> ForEachAsyncStream<TResult, TIn>(IEnumer
9197 {
9298 throw new ArgumentNullException ( nameof ( func ) ) ;
9399 }
100+ #endif //NET8_0_OR_GREATER
94101
95102 var maxBatchSizeToUse = DetermineBatchSizeToUse ( maxBatchSize ) ;
96103
@@ -319,12 +326,16 @@ private static async IAsyncEnumerable<TResult> ForEachAsyncStreamImplUnordered<T
319326 /// Setting this value to low, will mean a too small list will be allocated and you will have to pay a small performance hit for the resizing of the list during execution.
320327 /// </para>
321328 /// </remarks>
322- public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IAsyncEnumerable < TIn > collection , Func < TIn , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
329+ public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IAsyncEnumerable < TIn > collection , Func < TIn , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , CancellationToken cancellationToken = default )
323330 {
331+ #if NET8_0_OR_GREATER
332+ ArgumentNullException . ThrowIfNull ( func ) ;
333+ #else
324334 if ( func == null )
325335 {
326336 throw new ArgumentNullException ( nameof ( func ) ) ;
327337 }
338+ #endif //NET8_0_OR_GREATER
328339
329340 var funcWithCancellationToken = WrapFunc ( func ) ;
330341 return ForEachAsyncStream < TResult , TIn > ( collection , funcWithCancellationToken , maxBatchSize , allowOutOfOrderProcessing , estimatedResultSize , cancellationToken ) ;
@@ -358,8 +369,12 @@ public static IAsyncEnumerable<TResult> ForEachAsyncStream<TResult, TIn>(IAsyncE
358369 /// Setting this value to low, will mean a too small list will be allocated and you will have to pay a small performance hit for the resizing of the list during execution.
359370 /// </para>
360371 /// </remarks>
361- public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IAsyncEnumerable < TIn > collection , Func < TIn , CancellationToken , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
372+ public static IAsyncEnumerable < TResult > ForEachAsyncStream < TResult , TIn > ( IAsyncEnumerable < TIn > collection , Func < TIn , CancellationToken , Task < TResult > > func , int maxBatchSize = 0 , bool allowOutOfOrderProcessing = false , int estimatedResultSize = 0 , CancellationToken cancellationToken = default )
362373 {
374+ #if NET8_0_OR_GREATER
375+ ArgumentNullException . ThrowIfNull ( collection ) ;
376+ ArgumentNullException . ThrowIfNull ( func ) ;
377+ #else
363378 if ( collection == null )
364379 {
365380 throw new ArgumentNullException ( nameof ( collection ) ) ;
@@ -369,6 +384,7 @@ public static IAsyncEnumerable<TResult> ForEachAsyncStream<TResult, TIn>(IAsyncE
369384 {
370385 throw new ArgumentNullException ( nameof ( func ) ) ;
371386 }
387+ #endif //NET8_0_OR_GREATER
372388
373389 int maxBatchSizeToUse = DetermineBatchSizeToUse ( maxBatchSize ) ;
374390
@@ -555,8 +571,7 @@ private static async IAsyncEnumerable<TResult> ForEachAsyncStreamImplUnorderedAs
555571 ParallelAsyncEventSource . Log . RunStop ( runId ) ;
556572 }
557573
558- #endregion IAsyncEnumerable<T>
574+ #endregion IAsyncEnumerable<T>
559575 }
560576
561- #endif //NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_0_OR_GREATER
562577}
0 commit comments