Files
MWClash/lib/common/function.dart
chen08209 ef97ef40a1 Remake dashboard
Optimize theme

Optimize more details

Update flutter version
2025-01-09 10:10:06 +08:00

34 lines
569 B
Dart

import 'dart:async';
class Debouncer {
Map<dynamic, Timer> operators = {};
call(
dynamic tag,
Function func, {
List<dynamic>? args,
Duration duration = const Duration(milliseconds: 600),
}) {
final timer = operators[tag];
if (timer != null) {
timer.cancel();
}
operators[tag] = Timer(
duration,
() {
operators.remove(tag);
Function.apply(
func,
args,
);
},
);
}
cancel(dynamic tag) {
operators[tag]?.cancel();
}
}
final debouncer = Debouncer();