Skip to content

Instantly share code, notes, and snippets.

@bricelam
Created August 8, 2024 18:49
Show Gist options
  • Select an option

  • Save bricelam/cf286752898e51944377a36b83b1e2f7 to your computer and use it in GitHub Desktop.

Select an option

Save bricelam/cf286752898e51944377a36b83b1e2f7 to your computer and use it in GitHub Desktop.
Retry with Fibonacci backoff
var retry = 1;
var nextRetry = 1;
while (true)
{
try
{
DoSomething();
break;
}
catch (TransientException) when (retry <= 8)
{
Thread.Sleep(TimeSpan.FromMinutes(retry));
(retry, nextRetry) = (nextRetry, retry + nextRetry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment