mobile_skt/lib/util/throttler.dart

26 lines
396 B
Dart
Raw Normal View History

// throttle.dart
import 'dart:async';
/// 函数节流
///
/// [func]: 要执行的方法
Function throttler(
Future Function(String text) func,
) {
if (func == null) {
return func;
}
bool enable = true;
Function target = (String value) {
if (enable == true) {
enable = false;
func(value).then((_) {
enable = true;
});
}
};
return target;
}