From b5dcb7b4a70ad2a2d16efdc63946f914faac0d41 Mon Sep 17 00:00:00 2001 From: "jan.jansen" Date: Thu, 7 Jan 2021 11:27:31 +0100 Subject: [PATCH] Use linq instead of for loop --- src/Motor.Extensions.Hosting/QueuedGenericService.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Motor.Extensions.Hosting/QueuedGenericService.cs b/src/Motor.Extensions.Hosting/QueuedGenericService.cs index e0e09dc7..9778d8c6 100644 --- a/src/Motor.Extensions.Hosting/QueuedGenericService.cs +++ b/src/Motor.Extensions.Hosting/QueuedGenericService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; @@ -36,14 +37,9 @@ public QueuedGenericService( protected override async Task ExecuteAsync(CancellationToken token) { - var tasks = new List(); 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) @@ -58,6 +54,7 @@ private Task CreateRunnerTaskAsync(CancellationToken token) { continue; } + await HandleSingleMessageAsync(queueItem.Item, queueItem.TaskCompletionStatus, token) .ConfigureAwait(false); }