microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
436972edd2a63f773497d45cdc1de6342c7a1c20

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Common/Extensions/TaskExtensions.cs

29lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4namespace Microsoft.Teams.Common.Extensions;
5
6public static class TaskExtensions
7{
8 public static async Task<T> Retry<T>(Func<Task<T>> taskFactory, int max = 3, int delay = 200)
9 {
10 try
11 {
12 return await taskFactory().ConfigureAwait(false);
13 }
14 // don't retry cancelled
15 catch (OperationCanceledException) when (max > 0)
16 {
17 throw;
18 }
19 catch (Exception ex)
20 {
21 if (max > 0)
22 {
23 await Task.Delay(delay);
24 return await Retry(taskFactory, max - 1, delay * 2).ConfigureAwait(false);
25 }
26 throw new Exception(ex.Message, ex);
27 }
28 }
29}