throttle method

dynamic Function() throttle([
  1. Duration delay = const Duration(seconds: 1)
])

Throttle function When an event is triggered, the target operation is executed immediately. At the same time, a delayed time is given. If another event is triggered within that time range, the event is ignored and not processed until an event is triggered after the specified time range. For example, if the delay time is set to 1000ms: If another event is triggered within 1000ms, the event is ignored. If the delay of 1000ms expires, the event is not ignored, and the target operation is executed immediately. Then, another 1000ms delay is started.

Implementation

Function() throttle([Duration delay = const Duration(seconds: 1)]) {
  bool enable = _vxfuncThrottle[hashCode] ?? true;
  return () {
    if (enable) {
      _vxfuncThrottle[hashCode] = false;
      this.call();
      delay.delayed(() {
        _vxfuncThrottle.remove(hashCode);
      });
    }
  };
}