in edge-util/src/Microsoft.Azure.Devices.Edge.Util/transientFaultHandling/AsyncExecution[T].cs [113:157]
Task<TResult> ExecuteAsyncContinueWith(Task<TResult> runningTask)
{
if (!runningTask.IsFaulted || this.cancellationToken.IsCancellationRequested)
{
return runningTask;
}
TimeSpan zero;
Exception innerException = runningTask.Exception.InnerException;
#pragma warning disable CS0618 // Type or member is obsolete
if (innerException is RetryLimitExceededException)
#pragma warning restore CS0618 // Type or member is obsolete
{
var taskCompletionSource = new TaskCompletionSource<TResult>();
if (innerException.InnerException != null)
{
taskCompletionSource.TrySetException(innerException.InnerException);
}
else
{
taskCompletionSource.TrySetCanceled();
}
return taskCompletionSource.Task;
}
if (!this.isTransient(innerException) || !this.shouldRetry(this.retryCount++, innerException, out zero))
{
return runningTask;
}
if (zero < TimeSpan.Zero)
{
zero = TimeSpan.Zero;
}
this.onRetrying(this.retryCount, innerException, zero);
this.previousTask = runningTask;
if (zero > TimeSpan.Zero && (this.retryCount > 1 || !this.fastFirstRetry))
{
return Task.Delay(zero, this.cancellationToken).ContinueWith(new Func<Task, Task<TResult>>(this.ExecuteAsyncImpl), CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default).Unwrap();
}
return this.ExecuteAsyncImpl(null);
}