I'm trying to do the following using Polly. I have an ExecuteTask
async method, and I want to perform a conditional retry with a 200 ms wait. This is what I have so far:
The policy
AsyncRetryPolicy<SomeData> retryPolicy = AsyncPolicy
.HandleResult<SomeData>(s => s.IsCorrect == false)
.WaitAndRetry(1,
sleepDurationProvider: (retryCount, status, ctx) =>
{
return TimeSpan.FromMilliseconds(200);
},
onRetry: (response, timeSpan, retryCount, ctx) =>
{
Console.WriteLine($"Received a response of {response.Result}, retrying {retryCount}.");
});
The to-be-decorated method
private static async Task<SomeData> ExecuteTask()
{
return new SomeData() { IsCorrect= false };
}
The execution
var rslt = retryPolicy.ExecuteAsync(async () => {
return await ExecuteTask().ConfigureAwait(false);
});
SomeData
is just a class with a bool property, called IsCorrect
.
I can't seem the figure out how to define this policy. AsyncPolicy
does not contain a HandleResult()
method.