Skip to content

Commit

Permalink
Removes already-canceled token check.
Browse files Browse the repository at this point in the history
used to cover a rare use case, therefore the perf benefits were minimal.
  • Loading branch information
tommasobertoni committed Jan 24, 2021
1 parent 2a2f858 commit 32cec0c
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/NScatterGather/Aggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ public Aggregator(RecipientsCollection collection)
.Select(runner => runner.Start())
.ToArray();

if (cancellationToken.IsCancellationRequested)
return runners;

var allTasksCompleted = Task.WhenAll(tasks);

using (var cancellation = new CancellationTokenTaskSource<object?[]>(cancellationToken))
await Task.WhenAny(allTasksCompleted, cancellation.Task).ConfigureAwait(false);
using var cancellation = new CancellationTokenTaskSource<object?[]>(cancellationToken);
await Task.WhenAny(allTasksCompleted, cancellation.Task).ConfigureAwait(false);

if (cancellationToken.IsCancellationRequested)
await WaitForLatecomers(runners).ConfigureAwait(false);
Expand Down Expand Up @@ -103,13 +100,10 @@ public Aggregator(RecipientsCollection collection)
.Select(runner => runner.Start())
.ToArray();

if (cancellationToken.IsCancellationRequested)
return runners;

var allTasksCompleted = Task.WhenAll(tasks);

using (var cancellation = new CancellationTokenTaskSource<TResponse[]>(cancellationToken))
await Task.WhenAny(allTasksCompleted, cancellation.Task).ConfigureAwait(false);
using var cancellation = new CancellationTokenTaskSource<TResponse[]>(cancellationToken);
await Task.WhenAny(allTasksCompleted, cancellation.Task).ConfigureAwait(false);

if (cancellationToken.IsCancellationRequested)
await WaitForLatecomers(runners).ConfigureAwait(false);
Expand Down

0 comments on commit 32cec0c

Please sign in to comment.