Skip to content

Commit 838180a

Browse files
committed
refactor: remove dead code, arbitrary caps and unused API surface
- Remove GetPerformanceWarning: computed and immediately discarded in four constructors, never observable. - Remove arbitrary validation caps (10,000 tasks, 10,000 batch size, 24h timespan) that threw on legitimate large workloads. Negative/zero checks remain. - Add missing parallelism/batch/timespan validation to the result processor variants so all processors behave alike. - Strip unused equality ceremony, Deconstruct and AggressiveInlining (a no-op on async methods) from the TaskWrapper structs. - Remove the completed-task fast paths in ParallelExtensions: rethrowing GetBaseException destroyed stack traces and dropped sibling exceptions; awaiting is equivalent and correct. - LangVersion preview -> latest now that no preview features are used. - Update README disposal notes to match the non-blocking synchronous Dispose.
1 parent a303676 commit 838180a

11 files changed

Lines changed: 48 additions & 322 deletions

EnumerableAsyncProcessor.UnitTests/TaskWrapperStructValidationTests.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,6 @@ public async Task ItemTaskWrapper_ProcessesWithInput()
5959
await Assert.That(tcs.Task.IsCompletedSuccessfully).IsTrue();
6060
}
6161

62-
[Test]
63-
public async Task TaskWrapper_EqualityWorks()
64-
{
65-
// Arrange
66-
Func<Task> taskFactory = () => Task.CompletedTask;
67-
var tcs = new TaskCompletionSource();
68-
var wrapper1 = new ActionTaskWrapper(taskFactory, tcs);
69-
var wrapper2 = new ActionTaskWrapper(taskFactory, tcs);
70-
var wrapper3 = new ActionTaskWrapper(() => Task.CompletedTask, new TaskCompletionSource());
71-
72-
// Act & Assert
73-
await Assert.That(wrapper1.Equals(wrapper2)).IsTrue();
74-
await Assert.That(wrapper1 == wrapper2).IsTrue();
75-
await Assert.That(wrapper1.Equals(wrapper3)).IsFalse();
76-
await Assert.That(wrapper1 == wrapper3).IsFalse();
77-
}
78-
7962
[Test]
8063
public async Task TaskWrapper_ArrayStorage_WorksWithoutBoxing()
8164
{

EnumerableAsyncProcessor/EnumerableAsyncProcessor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net6.0;net8.0;net9.0;netstandard2.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<LangVersion>preview</LangVersion>
7+
<LangVersion>latest</LangVersion>
88
<Version>99.99.99</Version>
99
</PropertyGroup>
1010

EnumerableAsyncProcessor/Extensions/ParallelExtensions.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,8 @@ private static async Task<TResult> ProcessAsync<TSource, TResult>(
8383
semaphoreAcquired = true;
8484

8585
cancellationToken.ThrowIfCancellationRequested();
86-
var task = taskSelector(item);
87-
88-
// Fast-path optimization for already completed tasks
89-
if (task.IsCompleted)
90-
{
91-
if (task.IsFaulted)
92-
throw task.Exception?.GetBaseException() ?? task.Exception!;
93-
if (task.IsCanceled)
94-
throw new OperationCanceledException();
95-
return task.Result;
96-
}
9786

98-
// Await the task directly - it's already async so no need for Task.Run
99-
return await task.ConfigureAwait(false);
87+
return await taskSelector(item).ConfigureAwait(false);
10088
}
10189
finally
10290
{
@@ -121,20 +109,8 @@ private static async Task ProcessAsync<TSource>(
121109
semaphoreAcquired = true;
122110

123111
cancellationToken.ThrowIfCancellationRequested();
124-
var task = taskSelector(item);
125-
126-
// Fast-path optimization for already completed tasks
127-
if (task.IsCompleted)
128-
{
129-
if (task.IsFaulted)
130-
throw task.Exception?.GetBaseException() ?? task.Exception!;
131-
if (task.IsCanceled)
132-
throw new OperationCanceledException();
133-
return;
134-
}
135112

136-
// Await the task directly - it's already async so no need for Task.Run
137-
await task.ConfigureAwait(false);
113+
await taskSelector(item).ConfigureAwait(false);
138114
}
139115
finally
140116
{

EnumerableAsyncProcessor/RunnableProcessors/ResultProcessors/ResultBatchAsyncProcessor_2.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors.Abstract;
2+
using EnumerableAsyncProcessor.Validation;
23

34
namespace EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors;
45

@@ -9,6 +10,8 @@ public class ResultBatchAsyncProcessor<TInput, TOutput> : ResultAbstractAsyncPro
910
internal ResultBatchAsyncProcessor(int batchSize, IEnumerable<TInput> items, Func<TInput, Task<TOutput>> taskSelector,
1011
CancellationTokenSource cancellationTokenSource) : base(items, taskSelector, cancellationTokenSource)
1112
{
13+
ValidationHelper.ValidateBatchSize(batchSize);
14+
1215
_batchSize = batchSize;
1316
}
1417

EnumerableAsyncProcessor/RunnableProcessors/ResultProcessors/ResultRateLimitedParallelAsyncProcessor_1.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
using EnumerableAsyncProcessor.Extensions;
33
using EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors.Abstract;
4+
using EnumerableAsyncProcessor.Validation;
45

56
namespace EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors;
67

@@ -10,6 +11,8 @@ public class ResultRateLimitedParallelAsyncProcessor<TOutput> : ResultAbstractAs
1011

1112
internal ResultRateLimitedParallelAsyncProcessor(int count, Func<Task<TOutput>> taskSelector, int levelsOfParallelism, CancellationTokenSource cancellationTokenSource) : base(count, taskSelector, cancellationTokenSource)
1213
{
14+
ValidationHelper.ValidateParallelism(levelsOfParallelism);
15+
1316
_levelsOfParallelism = levelsOfParallelism;
1417
}
1518

EnumerableAsyncProcessor/RunnableProcessors/ResultProcessors/ResultRateLimitedParallelAsyncProcessor_2.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using EnumerableAsyncProcessor.Extensions;
22
using EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors.Abstract;
3+
using EnumerableAsyncProcessor.Validation;
34

45
namespace EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors;
56

@@ -9,6 +10,8 @@ public class ResultRateLimitedParallelAsyncProcessor<TInput, TOutput> : ResultAb
910

1011
internal ResultRateLimitedParallelAsyncProcessor(IEnumerable<TInput> items, Func<TInput, Task<TOutput>> taskSelector, int levelsOfParallelism, CancellationTokenSource cancellationTokenSource) : base(items, taskSelector, cancellationTokenSource)
1112
{
13+
ValidationHelper.ValidateParallelism(levelsOfParallelism);
14+
1215
_levelsOfParallelism = levelsOfParallelism;
1316
}
1417

EnumerableAsyncProcessor/RunnableProcessors/ResultProcessors/ResultTimedRateLimitedParallelAsyncProcessor_1.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using EnumerableAsyncProcessor.Extensions;
22
using EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors.Abstract;
3+
using EnumerableAsyncProcessor.Validation;
34

45
namespace EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors;
56

@@ -10,6 +11,9 @@ public class ResultTimedRateLimitedParallelAsyncProcessor<TOutput> : ResultAbstr
1011

1112
internal ResultTimedRateLimitedParallelAsyncProcessor(int count, Func<Task<TOutput>> taskSelector, int levelsOfParallelism, TimeSpan timeSpan, CancellationTokenSource cancellationTokenSource) : base(count, taskSelector, cancellationTokenSource)
1213
{
14+
ValidationHelper.ValidateParallelism(levelsOfParallelism);
15+
ValidationHelper.ValidateTimeSpan(timeSpan);
16+
1317
_levelsOfParallelism = levelsOfParallelism;
1418
_timeSpan = timeSpan;
1519
}

EnumerableAsyncProcessor/RunnableProcessors/ResultProcessors/ResultTimedRateLimitedParallelAsyncProcessor_2.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using EnumerableAsyncProcessor.Extensions;
22
using EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors.Abstract;
3+
using EnumerableAsyncProcessor.Validation;
34

45
namespace EnumerableAsyncProcessor.RunnableProcessors.ResultProcessors;
56

@@ -10,6 +11,9 @@ public class ResultTimedRateLimitedParallelAsyncProcessor<TInput, TOutput> : Res
1011

1112
internal ResultTimedRateLimitedParallelAsyncProcessor(IEnumerable<TInput> items, Func<TInput, Task<TOutput>> taskSelector, int levelsOfParallelism, TimeSpan timeSpan, CancellationTokenSource cancellationTokenSource) : base(items, taskSelector, cancellationTokenSource)
1213
{
14+
ValidationHelper.ValidateParallelism(levelsOfParallelism);
15+
ValidationHelper.ValidateTimeSpan(timeSpan);
16+
1317
_levelsOfParallelism = levelsOfParallelism;
1418
_timeSpan = timeSpan;
1519
}

0 commit comments

Comments
 (0)