@@ -8,9 +8,34 @@ public static partial class Extensions
88 /// <typeparam name="T">The item type.</typeparam>
99 /// <param name="reader">The channel reader to read from.</param>
1010 /// <param name="maxConcurrency">The maximum number of concurrent operations. Greater than 1 may likely cause results to be out of order.</param>
11+ /// <param name="taskCreationOptions">The task creation options to use.</param>
12+ /// <param name="scheduler">The task scheduler to use.</param>
1113 /// <param name="receiver">The async receiver function.</param>
12- /// <param name="cancellationToken">An optional cancellation token.</param>
14+ /// <param name="cancellationToken">The cancellation token.</param>
1315 /// <returns>A task that completes when no more reading is to be done.</returns>
16+ public static Task < long > ReadAllConcurrentlyAsync < T > ( this ChannelReader < T > reader ,
17+ int maxConcurrency ,
18+ TaskScheduler scheduler ,
19+ TaskCreationOptions taskCreationOptions ,
20+ Func < T , ValueTask > receiver ,
21+ CancellationToken cancellationToken = default )
22+ => Task . Factory
23+ . StartNew (
24+ ( ) => ReadAllConcurrentlyAsync ( reader , maxConcurrency , receiver , cancellationToken ) ,
25+ cancellationToken ,
26+ taskCreationOptions ,
27+ scheduler )
28+ . Unwrap ( ) ;
29+
30+ /// <inheritdoc cref="ReadAllConcurrentlyAsync{T}(ChannelReader{T}, int, TaskScheduler, TaskCreationOptions, Func{T, ValueTask}, CancellationToken)"/>
31+ public static Task < long > ReadAllConcurrentlyAsync < T > ( this ChannelReader < T > reader ,
32+ int maxConcurrency ,
33+ TaskScheduler scheduler ,
34+ Func < T , ValueTask > receiver ,
35+ CancellationToken cancellationToken = default )
36+ => ReadAllConcurrentlyAsync ( reader , maxConcurrency , scheduler , TaskCreationOptions . None , receiver , cancellationToken ) ;
37+
38+ /// <inheritdoc cref="ReadAllConcurrentlyAsync{T}(ChannelReader{T}, int, TaskScheduler, TaskCreationOptions, Func{T, ValueTask}, CancellationToken)"/>
1439 public static Task < long > ReadAllConcurrentlyAsync < T > ( this ChannelReader < T > reader ,
1540 int maxConcurrency ,
1641 Func < T , ValueTask > receiver ,
@@ -37,7 +62,7 @@ static async Task<long> ReadAllConcurrentlyAsyncCore(
3762 var readers = new Task < long > [ maxConcurrency ] ;
3863 var scheduler = TaskScheduler . Current ;
3964 for ( int r = 0 ; r < maxConcurrency ; ++ r )
40- readers [ r ] = Read ( ) ;
65+ readers [ r ] = Task . Factory . StartNew ( Read , cancellationToken , TaskCreationOptions . None , scheduler ) . Unwrap ( ) ;
4166
4267 // This produces the most accurate/reliable exception and cancellation results.
4368 return await Task
@@ -73,22 +98,33 @@ static async Task<long> SumAsync(Task<long[]> counts)
7398 }
7499 }
75100
76- /// <summary>
77- /// Reads items from the channel and passes them to the receiver.
78- /// </summary>
79- /// <typeparam name="T">The item type.</typeparam>
80- /// <param name="reader">The channel reader to read from.</param>
81- /// <param name="maxConcurrency">The maximum number of concurrent operations. Greater than 1 may likely cause results to be out of order.</param>
82- /// <param name="cancellationToken">The cancellation token.</param>
83- /// <param name="receiver">The async receiver function.</param>
84- /// <returns>A task that completes when no more reading is to be done.</returns>
101+ /// <inheritdoc cref="ReadAllConcurrentlyAsync{T}(ChannelReader{T}, int, TaskScheduler, TaskCreationOptions, Func{T, ValueTask}, CancellationToken)"/>
85102 [ SuppressMessage ( "Design" , "CA1068:CancellationToken parameters must come last" , Justification = "Provided for aesthetic convenience." ) ]
86103 public static Task < long > ReadAllConcurrentlyAsync < T > ( this ChannelReader < T > reader ,
87104 int maxConcurrency ,
88105 CancellationToken cancellationToken ,
89106 Func < T , ValueTask > receiver )
90107 => ReadAllConcurrentlyAsync ( reader , maxConcurrency , receiver , cancellationToken ) ;
91108
109+ /// <inheritdoc cref="ReadAllConcurrentlyAsync{T}(ChannelReader{T}, int, TaskScheduler, TaskCreationOptions, Func{T, ValueTask}, CancellationToken)"/>
110+ [ SuppressMessage ( "Design" , "CA1068:CancellationToken parameters must come last" , Justification = "Provided for aesthetic convenience." ) ]
111+ public static Task < long > ReadAllConcurrentlyAsync < T > ( this ChannelReader < T > reader ,
112+ int maxConcurrency ,
113+ TaskScheduler scheduler ,
114+ TaskCreationOptions taskCreationOptions ,
115+ CancellationToken cancellationToken ,
116+ Func < T , ValueTask > receiver )
117+ => ReadAllConcurrentlyAsync ( reader , maxConcurrency , scheduler , taskCreationOptions , receiver , cancellationToken ) ;
118+
119+ /// <inheritdoc cref="ReadAllConcurrentlyAsync{T}(ChannelReader{T}, int, TaskScheduler, TaskCreationOptions, Func{T, ValueTask}, CancellationToken)"/>
120+ [ SuppressMessage ( "Design" , "CA1068:CancellationToken parameters must come last" , Justification = "Provided for aesthetic convenience." ) ]
121+ public static Task < long > ReadAllConcurrentlyAsync < T > ( this ChannelReader < T > reader ,
122+ int maxConcurrency ,
123+ TaskScheduler scheduler ,
124+ CancellationToken cancellationToken ,
125+ Func < T , ValueTask > receiver )
126+ => ReadAllConcurrentlyAsync ( reader , maxConcurrency , scheduler , TaskCreationOptions . None , receiver , cancellationToken ) ;
127+
92128 /// <summary>
93129 /// Reads items from the channel and passes them to the receiver.
94130 /// </summary>
0 commit comments