I am working on a retry logic in a .NET Core WebAPI project. I'm using there polly where we have WaitAndRetryAsync
, WaitAndRetry
methods.
What is the difference between WaitAndRetryAsync
vs WaitAndRetry
?
And which one should be used when?
I am working on a retry logic in a .NET Core WebAPI project. I'm using there polly where we have WaitAndRetryAsync
, WaitAndRetry
methods.
What is the difference between WaitAndRetryAsync
vs WaitAndRetry
?
And which one should be used when?
When you use Polly you have to know upfront a couple of information about your to-be-decorated method/function to be able to define the policy in the correct way.
In case retry you can use 16 different methods to cover different use cases
If your to be decorated method does not return any value then use
Policy.Handle...
but if it returns with a specific type then prefer Policy<T>.Handle...
If your to-be-decorated method/function is synchronous then prefer those methods which does not have Async
suffix
But if you want to decorate an async method/function then prefer those with the Async
suffix
If you don't want to wait between retry attempts (so you want to kick off a new attempt immediately after the previous failed one) then prefer those methods which starts with Retry
If you do want to wait between attempts then use one of those methods where you have the Wait
prefix
If you know that your to-be-decorated method/function will eventually succeed but don't know after how many retry attempts then prefer those methods where the method name include Forever
If you don't know whether your to-be-decorated method/function will succeed eventually for sure and you don't want to wait indefinitely then prefer those methods which does not include the word Forever
so you can specific the maximum retry attempts