From 7e02e0f10621b129425a9f2dfa0ee580a047a4de Mon Sep 17 00:00:00 2001 From: Valera <50830352+ValeraFinebits@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:09:09 +0300 Subject: [PATCH] rethrow exception was added (#31) --- Sources/Tuvi.Core/TaskExtensions.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/Tuvi.Core/TaskExtensions.cs b/Sources/Tuvi.Core/TaskExtensions.cs index 5bdb147..255a95c 100644 --- a/Sources/Tuvi.Core/TaskExtensions.cs +++ b/Sources/Tuvi.Core/TaskExtensions.cs @@ -10,14 +10,25 @@ public static class TaskExtensions { public static async Task DoWithLogAsync(this IEnumerable tasks) { - var task = await Task.WhenAny(Task.WhenAll(tasks)).ConfigureAwait(false); - if (task.Exception is null) + try { - return; + await Task.WhenAll(tasks).ConfigureAwait(false); } - foreach (var ex in task.Exception.Flatten().InnerExceptions) + catch (Exception ex) { - LogException(LoggingExtension.Log(), ex); + if (ex is AggregateException aggregateException) + { + foreach (var innerEx in aggregateException.Flatten().InnerExceptions) + { + LogException(LoggingExtension.Log(), innerEx); + } + } + else + { + LogException(LoggingExtension.Log(), ex); + } + + throw; } }