call method
Execute an async function with debouncing Returns a future that completes when the debounced function executes
Implementation
Future<void> call(Future<void> Function() callback) {
// Cancel any pending timer
_timer?.cancel();
// Create a completer for this call
final completer = Completer<void>();
// Schedule the callback to run after the duration
_timer = Timer(duration, () async {
try {
await callback();
completer.complete();
} catch (e) {
completer.completeError(e);
}
});
return completer.future;
}