#throttle #debounce #eg

fns

添加常用函数,例如:debounce、throttle

1 个不稳定版本

0.0.7 2022年10月21日
0.0.6 2022年10月21日

#906数据结构

49 每月下载次数
2 crates 中使用

MIT/Apache

12KB
261

fns  

ci Latest Version downloads

fns = { version: "0" }

支持

* debounce
* throttle

debounce

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)

throttle

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)

依赖

~88KB