Skip to content

Commit

Permalink
Use linq instead of for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
farodin91 committed Jan 7, 2021
1 parent 2858b30 commit b5dcb7b
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Motor.Extensions.Hosting/QueuedGenericService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -36,14 +37,9 @@ public QueuedGenericService(

protected override async Task ExecuteAsync(CancellationToken token)
{
var tasks = new List<Task>();
var optionsParallelProcesses = _options.ParallelProcesses ?? Environment.ProcessorCount;
for (var i = 0; i < optionsParallelProcesses; i++)
{
tasks.Add(CreateRunnerTaskAsync(token));
}

await Task.WhenAll(tasks).ConfigureAwait(false);
await Task.WhenAll(Enumerable.Repeat(0, optionsParallelProcesses)
.Select(_ => CreateRunnerTaskAsync(token))).ConfigureAwait(false);
}

private Task CreateRunnerTaskAsync(CancellationToken token)
Expand All @@ -58,6 +54,7 @@ private Task CreateRunnerTaskAsync(CancellationToken token)
{
continue;
}

await HandleSingleMessageAsync(queueItem.Item, queueItem.TaskCompletionStatus, token)
.ConfigureAwait(false);
}
Expand Down

0 comments on commit b5dcb7b

Please sign in to comment.