将依赖事件总线的发布订阅模式,改为直接调用的形式

This commit is contained in:
yang.lee
2023-11-02 15:58:15 +08:00
parent 02e4dbb45a
commit b13574530d
32 changed files with 226 additions and 154 deletions

View File

@@ -25,6 +25,21 @@ namespace Tnb.Common.Extension
return tcs.Task;
}
public static async Task<T> Retry<T>(Func<Task<T>> task, int retries,
TimeSpan delay, CancellationToken cts = default) =>
await task().ContinueWith(async innerTask =>
{
cts.ThrowIfCancellationRequested();
if (innerTask.Status != TaskStatus.Faulted)
return innerTask.Result;
if (retries == 0)
throw innerTask.Exception ?? throw new Exception();
await Task.Delay(delay, cts);
return await Retry(task, retries - 1, delay, cts);
}).Unwrap();
public static async Task Catch(this Task task, Func<Exception,Task> exceptionHandler)
{
try