pub struct RpmTimer { /* private fields */ }Expand description
Use this struct to limit the speed of any items processing.
Adjust processing speed using struct’s methods.
Example usage:
extern crate rpm_timer;
use rpm_timer::RpmTimer;
fn main() {
let items = &["Hello", "World!", "How", "are", "you?"];
RpmTimer::default()
.rps_limit(1.0)
.max_threads(1)
.run_slice(items, print);
}
fn print(items: &[&str]) {
for item in items {
println!("{}", item);
}
}Implementations§
Source§impl RpmTimer
impl RpmTimer
Sourcepub fn tick(self, value: Duration) -> Self
pub fn tick(self, value: Duration) -> Self
Main thread will try to spawn working threads every tick.
Tip: yhe higher RPM requested, the lower tick duration should be.
Default: 100 ms
Sourcepub fn rpm_limit(self, value: f64) -> Self
pub fn rpm_limit(self, value: f64) -> Self
Target requests per minute number. It overrides the value previously set by rps_limit, if any.
Default: 60
Sourcepub fn rps_limit(self, value: f64) -> Self
pub fn rps_limit(self, value: f64) -> Self
Target requests per second number. It overrides the value previously set by rpm_limit, if any.
Default: 1
Sourcepub fn max_threads<T: Into<Option<usize>>>(self, value: T) -> Self
pub fn max_threads<T: Into<Option<usize>>>(self, value: T) -> Self
Maximum number of working threads in the pool.
Pass None to limit the number to the number of cpu cores (uses num_cpus under the hood).
Default: None
Sourcepub fn run_slice<T, F>(self, items: &[T], action: F)
pub fn run_slice<T, F>(self, items: &[T], action: F)
Non-allocating method that spawns thread and pass sub-slices to the workers.
This is the preffered way unless you only have an iterator.
It waits for all spawned threads to finish.