call method

void call(
  1. void block()
)

Schedules block to execute after _duration of inactivity.

If this is called again before _duration elapses, the previous timer is cancelled and a new one is started. Only the most recent call's action will execute.

Example:

debouncer(() => print('Executed'));
// ... 200ms later
debouncer(() => print('Cancelled - new timer started'));
// ... 500ms later
debouncer(() => print('This one will execute'));

Implementation

void call(void Function() block) {
  _timer?.cancel();
  _timer = .new(_duration, block);
}