pub struct LatencyInjector { /* private fields */ }Expand description
Computes per-attempt delays from a LatencyProfile.
LatencyInjector is intentionally side-effect-free: it returns
the delay it would sleep, leaving the actual thread::sleep
(or tokio::time::sleep) up to the caller. This keeps the type
usable in both sync and async contexts.
§Example
use dev_chaos::latency::{LatencyInjector, LatencyProfile};
use std::time::Duration;
let inj = LatencyInjector::new(LatencyProfile::Constant(Duration::from_millis(5)));
assert_eq!(inj.delay_for(1), Duration::from_millis(5));
assert_eq!(inj.delay_for(100), Duration::from_millis(5));Implementations§
Source§impl LatencyInjector
impl LatencyInjector
Sourcepub fn new(profile: LatencyProfile) -> Self
pub fn new(profile: LatencyProfile) -> Self
Build an injector from a profile.
Sourcepub fn delay_for(&self, attempt: usize) -> Duration
pub fn delay_for(&self, attempt: usize) -> Duration
Compute the delay that would be applied at attempt (1-indexed).
Sourcepub fn apply_blocking(&self, attempt: usize)
pub fn apply_blocking(&self, attempt: usize)
Apply the delay synchronously by sleeping the calling thread.
Equivalent to std::thread::sleep(self.delay_for(attempt)).
Auto Trait Implementations§
impl Freeze for LatencyInjector
impl RefUnwindSafe for LatencyInjector
impl Send for LatencyInjector
impl Sync for LatencyInjector
impl Unpin for LatencyInjector
impl UnsafeUnpin for LatencyInjector
impl UnwindSafe for LatencyInjector
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