23 lines
340 B
Dart
23 lines
340 B
Dart
|
// 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;
|
||
|
}
|