run method
void
run(
- void action()
Executes the action if the throttle is not currently active.
If run, the throttle becomes active immediately and will ignore subsequent calls until the duration has passed.
Implementation
void run(void Function() action) {
if (_isThrottled) return;
_isThrottled = true;
try {
action();
} finally {
// A zero/negative duration means "no cool-down" — keep the throttle
// open for the next call instead of paying for a Timer hop.
if (duration <= Duration.zero) {
_isThrottled = false;
} else {
_timer?.cancel();
_timer = Timer(duration, () {
_isThrottled = false;
_timer = null;
});
}
}
}