newtype RetryPolicyM m
A 'RetryPolicyM' is a function that takes an 'RetryStatus' and possibly returns a delay in milliseconds. Iteration numbers start at zero and increase by one on each retry. A Nothing return value from the function implies we have reached the retry limit.
Please note that 'RetryPolicyM' is a 'Monoid'. You can collapse multiple strategies into one using 'mappend' or '<>'. The semantics of this combination are as follows:
If either policy returns 'Nothing', the combined policy returns 'Nothing'. This can be used to @inhibit@ after a number of retries, for example.
If both policies return a delay, the larger delay will be used. This is quite natural when combining multiple policies to achieve a certain effect.
One can easily define an exponential backoff policy with a limited number of retries:
Naturally, 'mempty' will retry immediately (delay 0) for an unlimited number of retries, forming the identity for the 'Monoid'.
limitRetriesByDelay :: forall m d. Monad m => Duration d => d -> RetryPolicyM m -> RetryPolicyM m
Add an upperbound to a policy such that once the given time-delay amount per try has been reached or exceeded, the policy will stop retrying and fail. If you need to stop retrying once cumulative delay reaches a time-delay amount, use 'limitRetriesByCumulativeDelay'