26 lines
396 B
Dart
26 lines
396 B
Dart
// 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;
|
|
}
|