From d80e0d3562de369faa40e341935b16ce4a054b17 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 26 Nov 2025 21:47:23 +0100 Subject: [PATCH] Refactor HTTP requests to enable parallel execution Replaced sequential `foreach` loop with LINQ's `Select` to create a collection of tasks for sending HTTP requests asynchronously. Added `Task.WhenAll` to execute all requests concurrently, improving performance. Removed the old `foreach` implementation in favor of a functional programming approach. --- .../RecActions/Commands/InvokeRecActionCommand.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs index b13eb88..4d6ad11 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs @@ -21,7 +21,7 @@ public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory cl var http = clientFactory.CreateClient(); - foreach (var action in actions) + var tasks = actions.Select(async action => { var method = new HttpMethod(action.RestType.ToUpper()); var msg = new HttpRequestMessage(method, action.EndpointUri); @@ -29,6 +29,8 @@ public class InvokeRecActionCommandHandler(ISender sender, IHttpClientFactory cl var response = await http.SendAsync(msg, cancel); var body = await response.Content.ReadAsStringAsync(cancel); var headers = response.Headers.ToDictionary(); - } + }); + + await Task.WhenAll(tasks); } -} +} \ No newline at end of file