From 003336d731d3453301ed0ec98b5e19991af3e5b6 Mon Sep 17 00:00:00 2001 From: Misiu Date: Tue, 16 Apr 2019 15:57:16 +0200 Subject: [PATCH 1/6] Support IProgress in ParallelForEachAsync --- src/Extensions/ParallelForEachExtensions.cs | 41 +++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Extensions/ParallelForEachExtensions.cs b/src/Extensions/ParallelForEachExtensions.cs index acb032f..86b2f1e 100644 --- a/src/Extensions/ParallelForEachExtensions.cs +++ b/src/Extensions/ParallelForEachExtensions.cs @@ -165,6 +165,7 @@ private void OnCancelRequested() /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -174,6 +175,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParalellism, bool breakLoopOnException, bool gracefulBreak, + IProgress progress = null, CancellationToken cancellationToken = default) { if (collection == null) @@ -209,6 +211,7 @@ public static Task ParallelForEachAsync( try { itemActionTask = asyncItemAction(enumerator.Current, itemIndex); + progress?.Report(enumerator.Current); } // there is no guarantee that task is executed asynchronously, so it can throw right away catch (Exception ex) @@ -378,6 +381,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -424,6 +428,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -466,6 +471,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -510,6 +516,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -560,6 +567,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, + null, cancellationToken); /// @@ -608,6 +616,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -650,6 +659,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -694,6 +704,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -740,6 +751,32 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Report progress + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + IProgress progress, + CancellationToken cancellationToken = default) + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + progress, cancellationToken); /// @@ -782,6 +819,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -826,6 +864,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -872,6 +911,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// @@ -914,6 +954,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + null, cancellationToken); /// From 914efda29e640191b8a4220f40644cec0e44a9e5 Mon Sep 17 00:00:00 2001 From: Misiu Date: Wed, 17 Apr 2019 11:41:39 +0200 Subject: [PATCH 2/6] Added xml-doc comments for progress --- src/Extensions/ParallelForEachExtensions.cs | 48 ++++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Extensions/ParallelForEachExtensions.cs b/src/Extensions/ParallelForEachExtensions.cs index 86b2f1e..222893d 100644 --- a/src/Extensions/ParallelForEachExtensions.cs +++ b/src/Extensions/ParallelForEachExtensions.cs @@ -165,7 +165,7 @@ private void OnCancelRequested() /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception - /// + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -269,6 +269,7 @@ public static Task ParallelForEachAsync( /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -278,6 +279,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParalellism, bool breakLoopOnException, bool gracefulBreak, + IProgress progress = null, CancellationToken cancellationToken = default) { if (enumerator == null) @@ -311,6 +313,7 @@ public static Task ParallelForEachAsync( try { itemActionTask = asyncItemAction(enumerator.Current, itemIndex); + progress?.Report(enumerator.Current); } // there is no guarantee that task is executed asynchronously, so it can throw right away catch (Exception ex) @@ -381,7 +384,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -406,6 +409,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -428,7 +432,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -451,6 +455,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -471,7 +476,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -492,6 +497,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -516,7 +522,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -541,6 +547,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -567,7 +574,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, - null, + /*progress*/null, cancellationToken); /// @@ -594,6 +601,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, + /*progress*/null, cancellationToken); /// @@ -616,7 +624,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -639,6 +647,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -659,7 +668,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -680,6 +689,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -704,7 +714,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -729,6 +739,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -751,7 +762,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -761,7 +772,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Report progress + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -776,7 +787,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - progress, + /*progress*/progress, cancellationToken); /// @@ -799,6 +810,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -819,7 +831,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -840,6 +852,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -864,7 +877,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -889,6 +902,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -911,7 +925,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -934,6 +948,7 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -954,7 +969,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - null, + /*progress*/null, cancellationToken); /// @@ -975,6 +990,7 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); } } From 2f587bb89dd379da17e7a481aa87cc7d9b829689 Mon Sep 17 00:00:00 2001 From: Misiu Date: Wed, 17 Apr 2019 12:13:28 +0200 Subject: [PATCH 3/6] Added IProgress to other methods --- src/Extensions/ParallelForEachExtensions.cs | 102 +++++++++++++++----- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/src/Extensions/ParallelForEachExtensions.cs b/src/Extensions/ParallelForEachExtensions.cs index 222893d..1ddbe28 100644 --- a/src/Extensions/ParallelForEachExtensions.cs +++ b/src/Extensions/ParallelForEachExtensions.cs @@ -370,6 +370,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -378,13 +379,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -395,6 +397,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -403,13 +406,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -419,6 +423,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -426,13 +431,14 @@ public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -442,6 +448,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -449,13 +456,14 @@ public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -464,19 +472,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -485,19 +495,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -508,6 +520,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -516,13 +529,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -533,6 +547,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -541,13 +556,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -559,6 +575,7 @@ public static Task ParallelForEachAsync( /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -568,13 +585,14 @@ public static Task ParallelForEachAsync( int maxDegreeOfParalellism, bool breakLoopOnException, bool gracefulBreak, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -586,6 +604,7 @@ public static Task ParallelForEachAsync( /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -595,13 +614,14 @@ public static Task ParallelForEachAsync( int maxDegreeOfParalellism, bool breakLoopOnException, bool gracefulBreak, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -611,6 +631,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -618,13 +639,14 @@ public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -634,6 +656,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -641,13 +664,14 @@ public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -656,19 +680,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -677,19 +703,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -700,6 +728,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -708,13 +737,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -725,6 +755,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -733,13 +764,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -780,7 +812,7 @@ public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, int maxDegreeOfParalellism, - IProgress progress, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, @@ -797,6 +829,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -804,13 +837,14 @@ public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -819,19 +853,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -840,19 +876,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -863,6 +901,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -871,13 +910,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -888,6 +928,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -896,13 +937,14 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -912,6 +954,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -919,13 +962,14 @@ public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -935,6 +979,7 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -942,13 +987,14 @@ public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, int maxDegreeOfParalellism, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -957,19 +1003,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); /// @@ -978,19 +1026,21 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item + /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, + IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/null, + /*progress*/progress, cancellationToken); } } From f534c59cfcdf2fb37301d1b92943351aaaae2d69 Mon Sep 17 00:00:00 2001 From: Misiu Date: Wed, 17 Apr 2019 13:09:17 +0200 Subject: [PATCH 4/6] Added missing overrides --- src/Extensions/ParallelForEachExtensions.cs | 922 ++++++++++++++++---- 1 file changed, 753 insertions(+), 169 deletions(-) diff --git a/src/Extensions/ParallelForEachExtensions.cs b/src/Extensions/ParallelForEachExtensions.cs index 1ddbe28..03e5510 100644 --- a/src/Extensions/ParallelForEachExtensions.cs +++ b/src/Extensions/ParallelForEachExtensions.cs @@ -386,7 +386,32 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/progress, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -413,7 +438,32 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/progress, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -438,7 +488,30 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -463,7 +536,30 @@ public static Task ParallelForEachAsync( maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -486,7 +582,29 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + asyncItemAction, + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -509,7 +627,132 @@ public static Task ParallelForEachAsync( /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + asyncItemAction, + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + IProgress progress = null, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + IProgress progress = null, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -520,6 +763,7 @@ public static Task ParallelForEachAsync( /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -529,41 +773,411 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, - IProgress progress = null, + bool gracefulBreak, + IProgress progress = null, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + gracefulBreak, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + bool gracefulBreak, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + gracefulBreak, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + bool gracefulBreak, + IProgress progress = null, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + gracefulBreak, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + bool gracefulBreak, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + breakLoopOnException, + gracefulBreak, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + IProgress progress = null, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + IProgress progress = null, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + IProgress progress = null, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerable collection, + Func asyncItemAction, + CancellationToken cancellationToken = default) + => collection.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + IProgress progress = null, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IAsyncEnumerator enumerator, + Func asyncItemAction, + CancellationToken cancellationToken = default) + => enumerator.ParallelForEachAsync( + (item, index) => asyncItemAction(item), + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + IProgress progress = null, + CancellationToken cancellationToken = default) + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + CancellationToken cancellationToken = default) + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + /*progress*/null, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Use for progress updates + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, + IProgress progress = null, + CancellationToken cancellationToken = default) + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, + maxDegreeOfParalellism, + breakLoopOnException, + /*gracefulBreak:*/true, + progress, + cancellationToken); + + /// + /// Invokes an asynchronous action on each item in the collection in parallel + /// + /// The type of an item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. + /// Cancellation token + /// Wraps any exception(s) that occurred inside + /// Thrown when the loop is canceled with + public static Task ParallelForEachAsync( + this IEnumerator enumerator, + Func asyncItemAction, + int maxDegreeOfParalellism, + bool breakLoopOnException, CancellationToken cancellationToken = default) - => collection.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on - /// An asynchronous action to perform on the item + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerator enumerator, - Func asyncItemAction, + this IEnumerable collection, + Func asyncItemAction, int maxDegreeOfParalellism, - bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, maxDegreeOfParalellism, - breakLoopOnException, + /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// @@ -571,28 +1185,22 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. - /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception - /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerable collection, - Func asyncItemAction, + this IEnumerable collection, + Func asyncItemAction, int maxDegreeOfParalellism, - bool breakLoopOnException, - bool gracefulBreak, - IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, maxDegreeOfParalellism, - breakLoopOnException, - gracefulBreak, - /*progress*/progress, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + /*progress*/null, cancellationToken); /// @@ -600,78 +1208,70 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. - /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerator enumerator, - Func asyncItemAction, + this IEnumerator enumerator, + Func asyncItemAction, int maxDegreeOfParalellism, - bool breakLoopOnException, - bool gracefulBreak, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, maxDegreeOfParalellism, - breakLoopOnException, - gracefulBreak, - /*progress*/progress, + /*breakLoopOnException:*/false, + /*gracefulBreak:*/true, + progress, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on - /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Use for progress updates + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count.Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerable collection, - Func asyncItemAction, + this IEnumerator enumerator, + Func asyncItemAction, int maxDegreeOfParalellism, - IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on - /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerator enumerator, - Func asyncItemAction, - int maxDegreeOfParalellism, + this IEnumerable collection, + Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ParallelForEachAsync( - (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, + /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// @@ -679,22 +1279,20 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item - /// Use for progress updates + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerable collection, - Func asyncItemAction, - IProgress progress = null, + this IEnumerable collection, + Func asyncItemAction, CancellationToken cancellationToken = default) - => collection.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// @@ -702,57 +1300,51 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item + /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IAsyncEnumerator enumerator, - Func asyncItemAction, + this IEnumerator enumerator, + Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ParallelForEachAsync( - (item, index) => asyncItemAction(item), + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + asyncItemAction, /*maxDegreeOfParalellism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on + /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. - /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerable collection, + this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, - bool breakLoopOnException, - IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, - breakLoopOnException, + /*maxDegreeOfParalellism:*/0, + /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on - /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates @@ -760,18 +1352,18 @@ public static Task ParallelForEachAsync( /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerator enumerator, - Func asyncItemAction, + this IEnumerable collection, + Func asyncItemAction, int maxDegreeOfParalellism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( - asyncItemAction, + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + (item, index) => asyncItemAction(item), maxDegreeOfParalellism, breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// @@ -779,20 +1371,22 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerable collection, - Func asyncItemAction, + Func asyncItemAction, int maxDegreeOfParalellism, + bool breakLoopOnException, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( - asyncItemAction, + (item, index) => asyncItemAction(item), maxDegreeOfParalellism, - /*breakLoopOnException:*/false, + breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, cancellationToken); @@ -801,25 +1395,27 @@ public static Task ParallelForEachAsync( /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on - /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerable collection, - Func asyncItemAction, + this IEnumerator enumerator, + Func asyncItemAction, int maxDegreeOfParalellism, + bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( - asyncItemAction, + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + (item, index) => asyncItemAction(item), maxDegreeOfParalellism, - /*breakLoopOnException:*/false, + breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// @@ -827,24 +1423,24 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Use for progress updates + /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerator enumerator, - Func asyncItemAction, + Func asyncItemAction, int maxDegreeOfParalellism, - IProgress progress = null, + bool breakLoopOnException, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( - asyncItemAction, + (item, index) => asyncItemAction(item), maxDegreeOfParalellism, - /*breakLoopOnException:*/false, + breakLoopOnException, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// @@ -852,72 +1448,72 @@ public static Task ParallelForEachAsync( /// /// The type of an item /// The collection of items to perform actions on - /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerable collection, - Func asyncItemAction, + Func asyncItemAction, + int maxDegreeOfParalellism, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( - asyncItemAction, - /*maxDegreeOfParalellism:*/0, + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on - /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Use for progress updates + /// The collection of items to perform actions on + /// An asynchronous action to perform on the item + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerator enumerator, - Func asyncItemAction, - IProgress progress = null, + this IEnumerable collection, + Func asyncItemAction, + int maxDegreeOfParalellism, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( - asyncItemAction, - /*maxDegreeOfParalellism:*/0, + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + (item, index) => asyncItemAction(item), + maxDegreeOfParalellism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on + /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerable collection, + this IEnumerator enumerator, Func asyncItemAction, int maxDegreeOfParalellism, - bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, - breakLoopOnException, + /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// @@ -927,8 +1523,6 @@ public static Task ParallelForEachAsync( /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. - /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -936,15 +1530,13 @@ public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, int maxDegreeOfParalellism, - bool breakLoopOnException, - IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParalellism, - breakLoopOnException, + /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// @@ -953,7 +1545,6 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -961,63 +1552,58 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on + /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. - /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerator enumerator, + this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, - IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); /// /// Invokes an asynchronous action on each item in the collection in parallel /// /// The type of an item - /// The collection of items to perform actions on + /// The collection of items to perform actions on /// An asynchronous action to perform on the item /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( - this IEnumerable collection, + this IEnumerator enumerator, Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + progress, cancellationToken); /// @@ -1026,21 +1612,19 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, - /*progress*/progress, + /*progress*/null, cancellationToken); } -} +} \ No newline at end of file From eea8358ac39b1c601e32ba8ce45027d26c195e93 Mon Sep 17 00:00:00 2001 From: Misiu Date: Wed, 17 Apr 2019 13:11:49 +0200 Subject: [PATCH 5/6] Fixed typo in maxDegreeOfParalellism it should be maxDegreeOfParallelism --- src/Extensions/ParallelForEachExtensions.cs | 228 ++++++++++---------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/src/Extensions/ParallelForEachExtensions.cs b/src/Extensions/ParallelForEachExtensions.cs index 03e5510..f2d17e7 100644 --- a/src/Extensions/ParallelForEachExtensions.cs +++ b/src/Extensions/ParallelForEachExtensions.cs @@ -162,7 +162,7 @@ private void OnCancelRequested() /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Use for progress updates @@ -172,7 +172,7 @@ private void OnCancelRequested() public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, IProgress progress = null, @@ -183,7 +183,7 @@ public static Task ParallelForEachAsync( if (asyncItemAction == null) throw new ArgumentNullException(nameof(asyncItemAction)); - var context = new ParallelForEachContext(maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, cancellationToken); + var context = new ParallelForEachContext(maxDegreeOfParallelism, breakLoopOnException, gracefulBreak, cancellationToken); Task.Run( async () => @@ -266,7 +266,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Use for progress updates @@ -276,7 +276,7 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, IProgress progress = null, @@ -287,7 +287,7 @@ public static Task ParallelForEachAsync( if (asyncItemAction == null) throw new ArgumentNullException(nameof(asyncItemAction)); - var context = new ParallelForEachContext(maxDegreeOfParalellism, breakLoopOnException, gracefulBreak, cancellationToken); + var context = new ParallelForEachContext(maxDegreeOfParallelism, breakLoopOnException, gracefulBreak, cancellationToken); Task.Run( async () => @@ -368,7 +368,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -377,13 +377,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -395,7 +395,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -403,12 +403,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -420,7 +420,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -429,13 +429,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -447,7 +447,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -455,12 +455,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -472,7 +472,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -480,12 +480,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -497,18 +497,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -520,7 +520,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -528,12 +528,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -545,18 +545,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -657,7 +657,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -666,13 +666,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -684,7 +684,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -692,12 +692,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -709,7 +709,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -718,13 +718,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -736,7 +736,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -744,12 +744,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -761,7 +761,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Use for progress updates @@ -771,14 +771,14 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, gracefulBreak, progress, @@ -790,7 +790,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Cancellation token @@ -799,13 +799,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, gracefulBreak, /*progress*/null, @@ -817,7 +817,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Use for progress updates @@ -827,14 +827,14 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, gracefulBreak, progress, @@ -846,7 +846,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// If True (the default behavior), waits on completion for all started tasks when the loop breaks due to cancellation or an exception /// Cancellation token @@ -855,13 +855,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, gracefulBreak, /*progress*/null, @@ -873,7 +873,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -881,12 +881,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -898,18 +898,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -921,7 +921,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -929,12 +929,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -946,18 +946,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IAsyncEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1057,7 +1057,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -1066,13 +1066,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -1084,7 +1084,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1092,12 +1092,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -1109,7 +1109,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -1118,13 +1118,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -1136,7 +1136,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1144,12 +1144,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -1161,7 +1161,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1169,12 +1169,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1186,18 +1186,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1209,7 +1209,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1217,12 +1217,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1234,18 +1234,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count.Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count.Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( asyncItemAction, - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1345,7 +1345,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -1354,13 +1354,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -1372,7 +1372,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1380,12 +1380,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -1397,7 +1397,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Use for progress updates /// Cancellation token @@ -1406,13 +1406,13 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, progress, @@ -1424,7 +1424,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Set to True to stop processing items when first exception occurs. The result might contain several exceptions though when faulty tasks finish at the same time. /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1432,12 +1432,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, breakLoopOnException, /*gracefulBreak:*/true, /*progress*/null, @@ -1449,7 +1449,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1457,12 +1457,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1474,18 +1474,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1497,7 +1497,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Use for progress updates /// Cancellation token /// Wraps any exception(s) that occurred inside @@ -1505,12 +1505,12 @@ public static Task ParallelForEachAsync( public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1522,18 +1522,18 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. + /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, - int maxDegreeOfParalellism, + int maxDegreeOfParallelism, CancellationToken cancellationToken = default) => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( (item, index) => asyncItemAction(item), - maxDegreeOfParalellism, + maxDegreeOfParallelism, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, From 629a1714a280c599346377c1512e2a414c68c8d2 Mon Sep 17 00:00:00 2001 From: Misiu Date: Wed, 17 Apr 2019 13:19:16 +0200 Subject: [PATCH 6/6] Typos and other small fixes --- src/Extensions/ParallelForEachExtensions.cs | 106 ++++++++++---------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/Extensions/ParallelForEachExtensions.cs b/src/Extensions/ParallelForEachExtensions.cs index f2d17e7..1be2193 100644 --- a/src/Extensions/ParallelForEachExtensions.cs +++ b/src/Extensions/ParallelForEachExtensions.cs @@ -12,29 +12,29 @@ public static class ParallelForEachExtensions { private class ParallelForEachContext { - private SemaphoreSlim _semaphore; - private TaskCompletionSource _completionTcs; + private readonly SemaphoreSlim _semaphore; + private readonly TaskCompletionSource _completionTcs; private List _exceptionList; private SpinLock _exceptionListLock; - private readonly int _maxDegreeOfParalellism; + private readonly int _maxDegreeOfParallelism; private readonly bool _breakLoopOnException; private readonly bool _gracefulBreak; private CancellationToken _cancellationToken; private CancellationTokenRegistration _cancellationTokenRegistration; - public ParallelForEachContext(int maxDegreeOfParalellism, bool breakLoopOnException, bool gracefulBreak, CancellationToken cancellationToken) + public ParallelForEachContext(int maxDegreeOfParallelism, bool breakLoopOnException, bool gracefulBreak, CancellationToken cancellationToken) { - if (maxDegreeOfParalellism < 0) - throw new ArgumentException($"The maximum degree of parallelism must be a non-negative number, but got {maxDegreeOfParalellism}", nameof(maxDegreeOfParalellism)); - if (maxDegreeOfParalellism == 0) - maxDegreeOfParalellism = Environment.ProcessorCount - 1; - if (maxDegreeOfParalellism <= 0) - maxDegreeOfParalellism = 1; - - _semaphore = new SemaphoreSlim(initialCount: maxDegreeOfParalellism, maxCount: maxDegreeOfParalellism + 1); + if (maxDegreeOfParallelism < 0) + throw new ArgumentException($"The maximum degree of parallelism must be a non-negative number, but got {maxDegreeOfParallelism}", nameof(maxDegreeOfParallelism)); + if (maxDegreeOfParallelism == 0) + maxDegreeOfParallelism = Environment.ProcessorCount - 1; + if (maxDegreeOfParallelism <= 0) + maxDegreeOfParallelism = 1; + + _semaphore = new SemaphoreSlim(initialCount: maxDegreeOfParallelism, maxCount: maxDegreeOfParallelism + 1); _completionTcs = new TaskCompletionSource(); _exceptionListLock = new SpinLock(enableThreadOwnerTracking: false); - _maxDegreeOfParalellism = maxDegreeOfParalellism; + _maxDegreeOfParallelism = maxDegreeOfParallelism; _breakLoopOnException = breakLoopOnException; _gracefulBreak = gracefulBreak; @@ -109,7 +109,7 @@ public void OnOperationComplete(Exception exceptionIfFailed = null) return; } - if ((_semaphore.CurrentCount == _maxDegreeOfParalellism + 1) || (IsLoopBreakRequested && !_gracefulBreak)) + if ((_semaphore.CurrentCount == _maxDegreeOfParallelism + 1) || (IsLoopBreakRequested && !_gracefulBreak)) CompleteLoopNow(); } @@ -119,11 +119,11 @@ public void CompleteLoopNow() try { - if (_semaphore != null) - _semaphore.Dispose(); + _semaphore?.Dispose(); } catch { + // ignored } var exceptions = ReadExceptions(); @@ -579,7 +579,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -601,7 +601,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -624,7 +624,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -645,7 +645,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -980,7 +980,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1001,7 +1001,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => collection.ParallelForEachAsync( (item, index) => asyncItemAction(item), - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1024,7 +1024,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1045,7 +1045,7 @@ public static Task ParallelForEachAsync( CancellationToken cancellationToken = default) => enumerator.ParallelForEachAsync( (item, index) => asyncItemAction(item), - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1070,7 +1070,7 @@ public static Task ParallelForEachAsync( bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, breakLoopOnException, @@ -1095,7 +1095,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, breakLoopOnException, @@ -1122,7 +1122,7 @@ public static Task ParallelForEachAsync( bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, breakLoopOnException, @@ -1147,7 +1147,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, breakLoopOnException, @@ -1172,7 +1172,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1195,7 +1195,7 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParallelism, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1220,7 +1220,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1234,7 +1234,7 @@ public static Task ParallelForEachAsync( /// The type of an item /// The collection of items to perform actions on /// An asynchronous action to perform on the item, where first argument is the item and second argument is item's index in the collection - /// Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count.Maximum items to schedule processing in parallel. The actual concurrency level depends on TPL settings. Set to 0 to choose a default value based on processor count. /// Cancellation token /// Wraps any exception(s) that occurred inside /// Thrown when the loop is canceled with @@ -1243,7 +1243,7 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParallelism, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( asyncItemAction, maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1266,9 +1266,9 @@ public static Task ParallelForEachAsync( Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1287,9 +1287,9 @@ public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1310,9 +1310,9 @@ public static Task ParallelForEachAsync( Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, progress, @@ -1331,9 +1331,9 @@ public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( asyncItemAction, - /*maxDegreeOfParalellism:*/0, + /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, /*gracefulBreak:*/true, /*progress*/null, @@ -1358,7 +1358,7 @@ public static Task ParallelForEachAsync( bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, breakLoopOnException, @@ -1383,7 +1383,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, breakLoopOnException, @@ -1410,7 +1410,7 @@ public static Task ParallelForEachAsync( bool breakLoopOnException, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, breakLoopOnException, @@ -1435,7 +1435,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, bool breakLoopOnException, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, breakLoopOnException, @@ -1460,7 +1460,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1483,7 +1483,7 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParallelism, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1508,7 +1508,7 @@ public static Task ParallelForEachAsync( int maxDegreeOfParallelism, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1531,7 +1531,7 @@ public static Task ParallelForEachAsync( Func asyncItemAction, int maxDegreeOfParallelism, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( (item, index) => asyncItemAction(item), maxDegreeOfParallelism, /*breakLoopOnException:*/false, @@ -1554,7 +1554,7 @@ public static Task ParallelForEachAsync( Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, @@ -1575,7 +1575,7 @@ public static Task ParallelForEachAsync( this IEnumerable collection, Func asyncItemAction, CancellationToken cancellationToken = default) - => collection.ToAsyncEnumerable(runSynchronously: true).ParallelForEachAsync( + => collection.ToAsyncEnumerable().ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, @@ -1598,7 +1598,7 @@ public static Task ParallelForEachAsync( Func asyncItemAction, IProgress progress = null, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false, @@ -1619,7 +1619,7 @@ public static Task ParallelForEachAsync( this IEnumerator enumerator, Func asyncItemAction, CancellationToken cancellationToken = default) - => enumerator.ToAsyncEnumerator(runSynchronously: true).ParallelForEachAsync( + => enumerator.ToAsyncEnumerator().ParallelForEachAsync( (item, index) => asyncItemAction(item), /*maxDegreeOfParallelism:*/0, /*breakLoopOnException:*/false,