Files
umbrix/lib/core/utils/throttler.dart

17 lines
340 B
Dart
Raw Normal View History

2024-02-13 16:59:35 +03:30
import 'package:flutter/foundation.dart';
class Throttler {
Throttler(this.throttleFor);
final Duration throttleFor;
DateTime? _lastCall;
void call(VoidCallback callback) {
if (_lastCall == null ||
DateTime.now().difference(_lastCall!) > throttleFor) {
callback();
_lastCall = DateTime.now();
}
}
}