Timeout() public static method

Builds a Policy that will wait for a delegate to complete for a specified period of time. A TimeoutRejectedException will be thrown if the delegate does not complete within the configured timeout.
timeoutProvider
public static Timeout ( Func timeoutProvider ) : TimeoutPolicy
timeoutProvider Func A function to provide the timeout for this execution.
return Polly.Timeout.TimeoutPolicy
Exemplo n.º 1
0
        protected PolicyResult RetryAction(Action action, int timeoutInSeconds = 30, int retryIntervalInSeconds = 1)
        {
            Guard.NotNull(action, nameof(action), "Requires disposing function to be retried");
            Guard.NotLessThan(timeoutInSeconds, 0, nameof(timeoutInSeconds), "Requires a timeout (in sec) greater than zero");
            Guard.NotLessThan(retryIntervalInSeconds, 0, nameof(retryIntervalInSeconds), "Requires a retry interval (in sec) greater than zero");

            return(Policy.Timeout(TimeSpan.FromSeconds(timeoutInSeconds))
                   .Wrap(Policy.Handle <Exception>()
                         .WaitAndRetryForever(index => TimeSpan.FromSeconds(retryIntervalInSeconds)))
                   .ExecuteAndCapture(action));
        }