mobile_skt/lib/util/throttler.dart

23 lines
340 B
Dart
Raw Permalink Normal View History

2024-10-16 09:48:17 +08:00
// throttle.dart
import 'dart:async';
/// 函数节流
///
/// [func]: 要执行的方法
Function throttler(
Future Function(String text) func,
) {
bool enable = true;
target(String value) {
if (enable == true) {
enable = false;
func(value).then((_) {
enable = true;
});
}
}
return target;
}