Trait PollingPolicyExt

Source
pub trait PollingPolicyExt: PollingPolicy + Sized {
    // Provided methods
    fn with_time_limit(
        self,
        maximum_duration: Duration,
    ) -> LimitedElapsedTime<Self> { ... }
    fn with_attempt_limit(
        self,
        maximum_attempts: u32,
    ) -> LimitedAttemptCount<Self> { ... }
}
Expand description

Extension trait for PollingPolicy

Provided Methods§

Source

fn with_time_limit(self, maximum_duration: Duration) -> LimitedElapsedTime<Self>

Decorate a PollingPolicy to limit the total elapsed time in the polling loop.

While the time spent in the polling loop (including time in backoff) is less than the prescribed duration the on_error() method returns the results of the inner policy. After that time it returns Exhausted if the inner policy returns Continue.

§Example
use polling_policy::*;
use std::time::{Duration, Instant};
let policy = Aip194Strict.with_time_limit(Duration::from_secs(10)).with_attempt_limit(3);
let attempt_count = 4;
assert!(policy.on_error(Instant::now(), attempt_count, error::Error::authentication("transient")).is_exhausted());
Source

fn with_attempt_limit(self, maximum_attempts: u32) -> LimitedAttemptCount<Self>

Decorate a PollingPolicy to limit the number of poll attempts.

This policy decorates an inner policy and limits the total number of attempts. Note that on_error() is called only after a polling attempt. Therefore, setting the maximum number of attempts to 0 or 1 results in no polling after the LRO starts.

The policy passes through the results from the inner policy as long as attempt_count < maximum_attempts. Once the maximum number of attempts is reached, the policy returns Exhausted if the inner policy returns Continue, and passes the inner policy result otherwise.

§Example
use polling_policy::*;
use std::time::Instant;
let policy = Aip194Strict.with_attempt_limit(3);
assert!(policy.on_error(Instant::now(), 0, error::Error::authentication(format!("transient"))).is_continue());
assert!(policy.on_error(Instant::now(), 1, error::Error::authentication(format!("transient"))).is_continue());
assert!(policy.on_error(Instant::now(), 2, error::Error::authentication(format!("transient"))).is_continue());
assert!(policy.on_error(Instant::now(), 3, error::Error::authentication(format!("transient"))).is_exhausted());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§