Skip to content

Commit

Permalink
优化等待重试,异常也重试
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuDanK committed Jan 13, 2023
1 parent 497c42d commit cc585b1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions SageTools/Utils/ExtensionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ public static T DelayRetry<T>(Func<T> executeFunc, Func<T, bool> breakConditionF
while (retryCount > 0)
{
retryCount--;
res = executeFunc.Invoke();
if (breakConditionFunc.Invoke(res)) break;
Task.Delay(milliseconds).Wait();
try
{
res = executeFunc.Invoke();
if (breakConditionFunc.Invoke(res)) break;
Task.Delay(milliseconds).Wait();
}
catch
{
Task.Delay(milliseconds).Wait();
}
}

return res;
Expand All @@ -46,9 +53,16 @@ public static async Task<T> DelayRetryAsync<T>(Func<Task<T>> executeFunc, Func<T
while (retryCount > 0)
{
retryCount--;
res = await executeFunc.Invoke();
if (breakConditionFunc.Invoke(res)) break;
await Task.Delay(milliseconds);
try
{
res = await executeFunc.Invoke();
if (breakConditionFunc.Invoke(res)) break;
await Task.Delay(milliseconds);
}
catch
{
Task.Delay(milliseconds).Wait();
}
}

return res;
Expand Down

0 comments on commit cc585b1

Please sign in to comment.