microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Common/Extensions/TaskExtensions.cs
22lines · modecode
| 1 | namespace Microsoft.Teams.Common.Extensions; |
| 2 | |
| 3 | public static class TaskExtensions |
| 4 | { |
| 5 | public static async Task<T> Retry<T>(this Task<T> task, int max = 3, int delay = 200) |
| 6 | { |
| 7 | try |
| 8 | { |
| 9 | return await task.ConfigureAwait(false); |
| 10 | } |
| 11 | catch (Exception ex) |
| 12 | { |
| 13 | if (max > 0) |
| 14 | { |
| 15 | await Task.Delay(delay); |
| 16 | return await task.Retry(max - 1, delay * 2).ConfigureAwait(false); |
| 17 | } |
| 18 | |
| 19 | throw new Exception(ex.Message, ex); |
| 20 | } |
| 21 | } |
| 22 | } |