Struct rpm_timer::RpmTimer
[−]
[src]
pub struct RpmTimer { /* fields omitted */ }
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); } }
Methods
impl RpmTimer
[src]
fn tick(self, value: Duration) -> Self
[src]
Main thread will try to spawn working threads every tick.
Tip: yhe higher RPM requested, the lower tick duration should be.
Default: 100 ms
fn rpm_limit(self, value: f64) -> Self
[src]
Target requests per minute number. It overrides the value previously set by rps_limit
, if any.
Default: 60
fn rps_limit(self, value: f64) -> Self
[src]
Target requests per second number. It overrides the value previously set by rpm_limit
, if any.
Default: 1
fn max_threads<T: Into<Option<usize>>>(self, value: T) -> Self
[src]
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
fn run_slice<T, F>(self, items: &[T], action: F) where
F: Fn(&[T]) + Sync,
T: Send + Sync,
[src]
F: Fn(&[T]) + Sync,
T: Send + Sync,
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.
fn run_iter<T, I, F>(self, items: I, action: F) where
F: Fn(Vec<T>) + Sync,
I: Iterator<Item = T>,
T: Send,
[src]
F: Fn(Vec<T>) + Sync,
I: Iterator<Item = T>,
T: Send,
Allocating method that spawns thread and pass vectors with collected items to the workers.
This is the most generic solution but you should only use it when run_slice
is not possible..
It waits for all spawned threads to finish.