Skip to content

Commit acdf5b6

Browse files
committed
Support return object in logscope execute
1 parent 53abc16 commit acdf5b6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Yapoml.Framework/Logging/ILogScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ public interface ILogScope : IDisposable
2323

2424
void Execute(Action action);
2525

26-
void Execute(Func<Task> func);
26+
TResult Execute<TResult>(Func<TResult> func);
2727
}

src/Yapoml.Framework/Logging/LogScope.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,28 @@ public void Execute(Action action)
5353
}
5454
}
5555

56-
public void Execute(Func<Task> func)
56+
public TResult Execute<TResult>(Func<TResult> action)
5757
{
58+
TResult result;
59+
5860
try
5961
{
60-
func().GetAwaiter().GetResult();
62+
result = action();
63+
64+
var task = result as Task;
65+
66+
if (task is not null)
67+
{
68+
task.GetAwaiter().GetResult();
69+
}
6170
}
6271
catch (Exception ex)
6372
{
6473
Error = ex;
6574
throw;
6675
}
76+
77+
return result;
6778
}
6879

6980
public void Dispose()

0 commit comments

Comments
 (0)