run method
void
run(
- void action()
Runs action now if allowed, otherwise skips it (or queues it when trailing). throttler.run(save)
Implementation
void run(void Function() action) {
final DateTime now = DateTime.now();
if (_last == null || now.difference(_last!) >= interval) {
_last = now;
action();
return;
}
if (!trailing) return;
_queued = action;
_timer ??= Timer(interval - now.difference(_last!), () {
_timer = null;
final void Function()? next = _queued;
_queued = null;
if (next != null) run(next);
});
}