execute static method
Executes a function with cooldown and optional delay. Cancels any previous scheduled retry if not yet executed.
Implementation
static void execute(Function? callBack, {Duration? delay}) {
final now = DateTime.now();
// Throttle multiple rapid calls
if (_lastShownTime != null && now.difference(_lastShownTime!) < _cooldown) {
return;
}
_lastShownTime = now;
// Cancel any existing pending retry
cancel();
// Schedule or execute immediately
if (delay != null) {
_retryTimer = Timer(delay, () {
callBack?.call();
_retryTimer = null;
});
} else {
callBack?.call();
}
}