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 T LoopUntilSuccess<T>(
			Func<int, 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 func(i);
				}
				catch (Exception e)
				{
					exceptions.Add(e);
				}
				Thread.Sleep(sleepFunction(i));
			}
			throw new AggregateException("Retry count of " + maxAttempts + " exceeded", exceptions.ToArray());
		}
public static T LoopUntilSuccess < T > ( Func < int , 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 func ( i ) ; } catch ( Exception e ) { exceptions . Add ( e ) ; } Thread . Sleep ( 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, T>
sleepFunction
Func<int, TimeSpan>
maxAttempts
int?