mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
24 lines
336 B
Dart
24 lines
336 B
Dart
import 'dart:async';
|
|
|
|
class Debounce {
|
|
Debounce({
|
|
this.duration = const Duration(milliseconds: 1000),
|
|
});
|
|
|
|
final Duration duration;
|
|
Timer? _timer;
|
|
|
|
void call(Function action) {
|
|
dispose();
|
|
|
|
_timer = Timer(duration, () {
|
|
action();
|
|
});
|
|
}
|
|
|
|
void dispose() {
|
|
_timer?.cancel();
|
|
_timer = null;
|
|
}
|
|
}
|