Skip to content

Commit 6936e44

Browse files
authored
Add Parallel.ForEachAsync (#46943)
* Add Parallel.ForEachAsync * Address PR feedback and add a few more tests Also clean up a few things in the src, adding a few more asserts and moving nullable suppressions closer to the point where they're relevant.
1 parent c0038ab commit 6936e44

File tree

7 files changed

+1573
-9
lines changed

7 files changed

+1573
-9
lines changed

src/libraries/System.Threading.Tasks.Parallel/ref/System.Threading.Tasks.Parallel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public static partial class Parallel
3636
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource, TLocal>(System.Collections.Generic.IEnumerable<TSource> source, System.Func<TLocal> localInit, System.Func<TSource, System.Threading.Tasks.ParallelLoopState, TLocal, TLocal> body, System.Action<TLocal> localFinally) { throw null; }
3737
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource, TLocal>(System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, System.Func<TLocal> localInit, System.Func<TSource, System.Threading.Tasks.ParallelLoopState, long, TLocal, TLocal> body, System.Action<TLocal> localFinally) { throw null; }
3838
public static System.Threading.Tasks.ParallelLoopResult ForEach<TSource, TLocal>(System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, System.Func<TLocal> localInit, System.Func<TSource, System.Threading.Tasks.ParallelLoopState, TLocal, TLocal> body, System.Action<TLocal> localFinally) { throw null; }
39+
public static System.Threading.Tasks.Task ForEachAsync<TSource>(System.Collections.Generic.IEnumerable<TSource> source, System.Func<TSource, CancellationToken, ValueTask> body) { throw null; }
40+
public static System.Threading.Tasks.Task ForEachAsync<TSource>(System.Collections.Generic.IEnumerable<TSource> source, CancellationToken cancellationToken, System.Func<TSource, CancellationToken, ValueTask> body) { throw null; }
41+
public static System.Threading.Tasks.Task ForEachAsync<TSource>(System.Collections.Generic.IEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, System.Func<TSource, CancellationToken, ValueTask> body) { throw null; }
42+
public static System.Threading.Tasks.Task ForEachAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource> source, System.Func<TSource, CancellationToken, ValueTask> body) { throw null; }
43+
public static System.Threading.Tasks.Task ForEachAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource> source, CancellationToken cancellationToken, System.Func<TSource, CancellationToken, ValueTask> body) { throw null; }
44+
public static System.Threading.Tasks.Task ForEachAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource> source, System.Threading.Tasks.ParallelOptions parallelOptions, System.Func<TSource, CancellationToken, ValueTask> body) { throw null; }
3945
public static System.Threading.Tasks.ParallelLoopResult For<TLocal>(int fromInclusive, int toExclusive, System.Func<TLocal> localInit, System.Func<int, System.Threading.Tasks.ParallelLoopState, TLocal, TLocal> body, System.Action<TLocal> localFinally) { throw null; }
4046
public static System.Threading.Tasks.ParallelLoopResult For<TLocal>(int fromInclusive, int toExclusive, System.Threading.Tasks.ParallelOptions parallelOptions, System.Func<TLocal> localInit, System.Func<int, System.Threading.Tasks.ParallelLoopState, TLocal, TLocal> body, System.Action<TLocal> localFinally) { throw null; }
4147
public static System.Threading.Tasks.ParallelLoopResult For<TLocal>(long fromInclusive, long toExclusive, System.Func<TLocal> localInit, System.Func<long, System.Threading.Tasks.ParallelLoopState, TLocal, TLocal> body, System.Action<TLocal> localFinally) { throw null; }

src/libraries/System.Threading.Tasks.Parallel/src/Resources/Strings.resx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@
6464
<value>This method requires the use of an OrderedPartitioner with the KeysNormalized property set to true.</value>
6565
</data>
6666
<data name="Parallel_ForEach_PartitionerNotDynamic" xml:space="preserve">
67-
<value>The Partitioner used here must support dynamic partitioning.</value>
67+
<value>The Partitioner must support dynamic partitioning.</value>
6868
</data>
6969
<data name="Parallel_ForEach_PartitionerReturnedNull" xml:space="preserve">
70-
<value>The Partitioner used here returned a null partitioner source.</value>
70+
<value>The Partitioner returned a null partitioner source.</value>
7171
</data>
7272
<data name="Parallel_ForEach_NullEnumerator" xml:space="preserve">
73-
<value>The Partitioner source returned a null enumerator.</value>
73+
<value>The source returned a null enumerator.</value>
7474
</data>
7575
<data name="ParallelState_Break_InvalidOperationException_BreakAfterStop" xml:space="preserve">
7676
<value>Break was called after Stop was called.</value>
@@ -81,4 +81,4 @@
8181
<data name="ParallelState_NotSupportedException_UnsupportedMethod" xml:space="preserve">
8282
<value>This method is not supported.</value>
8383
</data>
84-
</root>
84+
</root>

src/libraries/System.Threading.Tasks.Parallel/src/System.Threading.Tasks.Parallel.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<Compile Include="System\Threading\Tasks\Parallel.cs" />
10+
<Compile Include="System\Threading\Tasks\Parallel.ForEachAsync.cs" />
1011
<Compile Include="System\Threading\Tasks\ParallelETWProvider.cs" />
1112
<Compile Include="System\Threading\Tasks\ParallelLoopState.cs" />
1213
<Compile Include="System\Threading\Tasks\ParallelRangeManager.cs" />
1314
<Compile Include="System\Threading\Tasks\TaskReplicator.cs" />
1415
</ItemGroup>
1516
<ItemGroup>
17+
<Reference Include="System.Collections" />
1618
<Reference Include="System.Collections.Concurrent" />
1719
<Reference Include="System.Diagnostics.Tracing" />
1820
<Reference Include="System.Runtime" />
1921
<Reference Include="System.Runtime.Extensions" />
2022
<Reference Include="System.Threading" />
2123
<Reference Include="System.Threading.Tasks" />
24+
<Reference Include="System.Threading.ThreadPool" />
2225
</ItemGroup>
2326
</Project>

0 commit comments

Comments
 (0)