mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-06-29 02:03:10 -04:00
* chore: add keep alive to ai writer block component * chore: allow user scrolling during ai writer generation * chore: pull ai writer cubit upwards * test: fix unit tests * chore: clear selection
27 lines
415 B
Dart
27 lines
415 B
Dart
import 'dart:async';
|
|
|
|
class Throttler {
|
|
Throttler({
|
|
this.duration = const Duration(milliseconds: 1000),
|
|
});
|
|
|
|
final Duration duration;
|
|
Timer? _timer;
|
|
|
|
void call(Function callback) {
|
|
if (_timer?.isActive ?? false) return;
|
|
|
|
_timer = Timer(duration, () {
|
|
callback();
|
|
});
|
|
}
|
|
|
|
void cancel() {
|
|
_timer?.cancel();
|
|
}
|
|
|
|
void dispose() {
|
|
_timer?.cancel();
|
|
_timer = null;
|
|
}
|
|
}
|