Async Concepts
Retry Plan
Model retry attempts before an operation succeeds.
Retry Plan
RetryPlan.cs
using System;
class Program
{
static void Main()
{
int failuresBeforeSuccess = ;
int maxAttempts = 3;
int attempt = 0;
string status = "failed";
while (attempt < maxAttempts)
{
attempt++;
if (attempt > failuresBeforeSuccess)
{
status = "success";
break;
}
Console.WriteLine($"retryAfter={attempt}");
}
Console.WriteLine($"attempts={attempt}");
Console.WriteLine($"status={status}");
}
}
using System;
class Program
{
static void Main()
{
int failuresBeforeSuccess = ;
int maxAttempts = 3;
int attempt = 0;
string status = "failed";
while (attempt < maxAttempts)
{
attempt++;
if (attempt > failuresBeforeSuccess)
{
status = "success";
break;
}
Console.WriteLine($"retryAfter={attempt}");
}
Console.WriteLine($"attempts={attempt}");
Console.WriteLine($"status={status}");
}
}
using System;
class Program
{
static void Main()
{
int failuresBeforeSuccess = ;
int maxAttempts = 3;
int attempt = 0;
string status = "failed";
while (attempt < maxAttempts)
{
attempt++;
if (attempt > failuresBeforeSuccess)
{
status = "success";
break;
}
Console.WriteLine($"retryAfter={attempt}");
}
Console.WriteLine($"attempts={attempt}");
Console.WriteLine($"status={status}");
}
}
async
Async calls to remote resources often retry failed attempts, but the retry policy can be modeled with ordinary control flow.