pub struct Retry { /* private fields */ }
Available on crate feature network only.
Expand description

Configures a retry operation.

See the module documentation for usage examples.

Implementations

Sets the initial backoff for the retry operation.

The initial backoff is the amount of time to wait if the first try fails.

Clamps the maximum backoff for the retry operation.

The maximum backoff is the maximum amount of time to wait between tries.

Sets the exponential backoff factor for the retry operation.

The time to wait is multiplied by this factor after each failed try. The default factor is two.

Sets the maximum number of tries.

If the operation is still failing after max_tries, then retry will return the last error.

Calls to max_tries will override any previous calls to max_tries.

Panics

Panics if max_tries is zero.

Sets the maximum duration.

If the operation is still failing after the specified duration, then the operation will be retried once more and retry will return the last error.

Calls to max_duration will override any previous calls to max_duration.

Retries the fallible operation f according to the configured policy.

The retry method invokes f repeatedly until it succeeds or until the maximum duration or tries have been reached, as configured via max_duration or max_tries. If f never succeeds, then retry returns f’s return value from its last invocation.

After the first failure, retry sleeps for the initial backoff configured via initial_backoff. After each successive failure, retry sleeps for twice the last backoff. If the backoff would ever exceed the maximum backoff configured viq Retry::clamp_backoff, then the backoff is clamped to the specified maximum.

The operation does not attempt to forcibly time out f, even if there is a maximum duration. If there is the possibility of f blocking forever, consider adding a timeout internally.

Like Retry::retry but for asynchronous operations.

Like Retry::retry_async but the operation will be canceled if the maximum duration is reached.

Specifically, if the maximum duration is reached, the operation f will be forcibly canceled by dropping it. Canceling f can be surprising if the operation is not programmed to expect the possibility of not resuming from an await point; if you wish to always run f to completion, use Retry::retry_async instead.

If f is forcibly canceled, the error returned will be the error returned by the prior invocation of f. If there is no prior invocation of f, then an Elapsed error is returned. The idea is that if f fails three times in a row with a useful error message, and then the fourth attempt is canceled because the timeout is reached, the caller would rather see the useful error message from the third attempt, rather than the “deadline exceeded” message from the fourth attempt.

Convert into RetryStream

Trait Implementations

Formats the value using the given formatter. Read more

Constructs a retry operation that will retry forever with backoff defaults that are reasonable for a fallible network operation.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap the input message T in a tonic::Request

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more