Crates.io | fns |
lib.rs | fns |
version | 0.0.7 |
source | src |
created_at | 2022-10-20 07:32:12.351399 |
updated_at | 2022-10-21 09:37:07.155048 |
description | add common fn, eg: debounce, throttle ... |
homepage | |
repository | https://github.com/cargo-crates/fns |
max_upload_size | |
id | 692212 |
size | 11,420 |
fns = { version: "0" }
* debounce
* throttle
let debounce_fn = fns::debounce(|param: usize| {
println!("{}", param);
}, std::time::Duration::from_secs(1));
debounce_fn.call(1); // skip
debounce_fn.call(2); // run after 1 second
// debounce_fn.terminate() // cancel call(2)
let throttle_fn = fns::throttle(|param: usize| {
println!("{}", param);
}, std::time::Duration::from_secs(1));
throttle_fn.call(1); // run immediate
throttle_fn.call(2); // skip
throttle_fn.call(3); // last call will run after 1 second
// throttle_fn.terminate(); // cancel call(3)