Source/Common/Core/FileOperations/RetryLoop.cs
/// <summary>
/// Retries func until it succeeds or the specified maximum number of attempts is reached
/// </summary>
/// <exception cref="AggregateException"></exception>
Retries func until it succeeds or the specified maximum number of attempts is reached
Retries func until it succeeds or the specified maximum number of attempts is reached
public static async Task<T> AsyncLoopUntilSuccess<T>(
			Func<int, Task<T>> func,
			Func<int, TimeSpan> sleepFunction = null,
			int? maxAttempts = null)
		{
			sleepFunction = sleepFunction ?? SleepFunctions.DiskRetry;
			var exceptions = new List<Exception>();
			for (int i = 0; maxAttempts.HasValue == false || i < maxAttempts; i++)
			{
				try
				{
					return await func(i);
				}
				catch (Exception e)
				{
					exceptions.Add(e);
				}
				await Task.Delay(sleepFunction(i));
			}
			throw new AggregateException("Retry count of " + maxAttempts + " exceeded", exceptions.ToArray());
		}
public static async Task < T > AsyncLoopUntilSuccess < T > ( Func < int , Task < T > > func , Func < int , TimeSpan > sleepFunction = null , int ? maxAttempts = null ) { sleepFunction = sleepFunction ?? SleepFunctions . DiskRetry ; var exceptions = new List < Exception > ( ) ; for ( int i = 0 ; maxAttempts . HasValue == false || i < maxAttempts ; i ++ ) { try { return await func ( i ) ; } catch ( Exception e ) { exceptions . Add ( e ) ; } await Task . Delay ( sleepFunction ( i ) ) ; } throw new AggregateException ( " " + maxAttempts + " " , exceptions . ToArray ( ) ) ; }
Retries func until it succeeds or the specified maximum number of attempts is reached
Retries func until it succeeds or the specified maximum number of attempts is reached
None
func
Func<int, Task<T>>
sleepFunction
Func<int, TimeSpan>
maxAttempts
int?