Skip to content

Commit

Permalink
rethrow exception was added (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeraFinebits committed Jun 29, 2024
1 parent e0ba259 commit 7e02e0f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Sources/Tuvi.Core/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ public static class TaskExtensions
{
public static async Task DoWithLogAsync<T>(this IEnumerable<Task> 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<T>(), ex);
if (ex is AggregateException aggregateException)
{
foreach (var innerEx in aggregateException.Flatten().InnerExceptions)
{
LogException(LoggingExtension.Log<T>(), innerEx);
}
}
else
{
LogException(LoggingExtension.Log<T>(), ex);
}

throw;
}
}

Expand Down

0 comments on commit 7e02e0f

Please sign in to comment.