pub struct JitterDelayLayer { /* private fields */ }Available on crate feature
tower-delay only.Expand description
A Tower Layer that introduces a jittered delay before each request.
The actual delay for each request will be randomly chosen within the range
[base - base*pct, base + base*pct].
§Example
use std::time::Duration;
use wreq::Client;
use wreq_util::middleware::delay::JitterDelayLayer;
// Creates delays in range [0.8s, 1.2s] (1s ± 20%)
let client = Client::builder()
.layer(JitterDelayLayer::new(Duration::from_secs(1), 0.2))
.build()?;Implementations§
Source§impl JitterDelayLayer
impl JitterDelayLayer
Sourcepub fn new(base: Duration, pct: f64) -> Self
pub fn new(base: Duration, pct: f64) -> Self
Create a new JitterDelayLayer with the given base delay and jitter percentage.
§Arguments
base- The base delay durationpct- The jitter percentage (0.0 to 1.0), representing ±pct deviation
§Example
use std::time::Duration;
use wreq_util::middleware::delay::JitterDelayLayer;
// Creates delays in range [800ms, 1200ms]
let layer = JitterDelayLayer::new(Duration::from_secs(1), 0.2);Sourcepub fn when<P, Req>(self, predicate: P) -> JitterDelayLayerWith<P>
pub fn when<P, Req>(self, predicate: P) -> JitterDelayLayerWith<P>
Apply jitter delay only to requests that satisfy a predicate.
Requests that don’t match the predicate will pass through without delay.
§Example
ⓘ
use std::time::Duration;
use http::Request;
use wreq_util::middleware::delay::JitterDelayLayer;
// Only delay requests to paths starting with "/slow"
let layer = JitterDelayLayer::new(Duration::from_secs(1), 0.2)
.when(|req: &Request<_>| req.uri().path().starts_with("/slow"));Trait Implementations§
Source§impl Clone for JitterDelayLayer
impl Clone for JitterDelayLayer
Source§fn clone(&self) -> JitterDelayLayer
fn clone(&self) -> JitterDelayLayer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JitterDelayLayer
impl Debug for JitterDelayLayer
Auto Trait Implementations§
impl Freeze for JitterDelayLayer
impl RefUnwindSafe for JitterDelayLayer
impl Send for JitterDelayLayer
impl Sync for JitterDelayLayer
impl Unpin for JitterDelayLayer
impl UnsafeUnpin for JitterDelayLayer
impl UnwindSafe for JitterDelayLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more