michael-wolfenden/Polly — pull request #13 by mauricedb (2014-11-02 16:30:54+00:00)
Title: Add async support to Polly

I added asynchronous support to the .NET 4.5 version Polly. Doing external IO is one of the kinds of job where a retry policy is most likely to be effective at resolving an exception. As with .NET 4.5 that is typically done with async/await instead of with a blocking call.

Example usage:

try
{
Result.Text = "Executing";

var policy = Policy.Handle()
.WaitAndRetry(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(2),
TimeSpan.FromSeconds(3)
});

var html = await policy.ExecuteAsync(() =>
{
var client = new HttpClient();
return client.GetStringAsync("http://google.com");
});

Result.Text = html;
}
catch (Exception ex)
{
Result.Text = ex.ToString();
}