microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

29lines · modeblame

82a4e3c3Rajan1 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
73e7847aAlex Acebo1 years ago4namespace Microsoft.Teams.Common.Extensions;
5
6public static class TaskExtensions
7{
852883e1Mehak Bindra10 months ago8public static async Task<T> Retry<T>(Func<Task<T>> taskFactory, int max = 3, int delay = 200)
73e7847aAlex Acebo1 years ago9{
5879f0e2Alex Acebo1 years ago10try
73e7847aAlex Acebo1 years ago11{
852883e1Mehak Bindra10 months ago12return await taskFactory().ConfigureAwait(false);
13}
14// don't retry cancelled
15catch (OperationCanceledException) when (max > 0)
16{
17throw;
73e7847aAlex Acebo1 years ago18}
5879f0e2Alex Acebo1 years ago19catch (Exception ex)
977f5b29Alex Acebo1 years ago20{
5879f0e2Alex Acebo1 years ago21if (max > 0)
73e7847aAlex Acebo1 years ago22{
5879f0e2Alex Acebo1 years ago23await Task.Delay(delay);
852883e1Mehak Bindra10 months ago24return await Retry(taskFactory, max - 1, delay * 2).ConfigureAwait(false);
73e7847aAlex Acebo1 years ago25}
5879f0e2Alex Acebo1 years ago26throw new Exception(ex.Message, ex);
27}
73e7847aAlex Acebo1 years ago28}
29}