LighthouseApp/lib/utils/callback_debouncer.dart
speakeloudest 75d4c48e41
Some checks failed
Build Windows / build (push) Has been cancelled
feat: 源码提交
2025-10-19 23:30:54 -07:00

26 lines
523 B
Dart
Executable File

import 'dart:async';
import 'package:flutter/foundation.dart';
class CallbackDebouncer {
CallbackDebouncer(this._delay);
final Duration _delay;
Timer? _timer;
/// Calls the given [callback] after the given duration has passed.
void call(VoidCallback callback) {
if (_delay == Duration.zero) {
callback();
} else {
_timer?.cancel();
_timer = Timer(_delay, callback);
}
}
/// Stops any running timers and disposes this instance.
void dispose() {
_timer?.cancel();
}
}