throttle method

void throttle(
  1. T value
)

Implementation

void throttle(T value) {
  final key = _generateKey();
  if (_funcThrottle[key] ?? true) {
    _funcThrottle[key] = false;
    target?.call(value);
    Timer(Duration(milliseconds: timeout), () {
      _funcThrottle.remove(key);
      if (trailing && (_throttlePending[key] ?? false)) {
        _throttlePending.remove(key);
        final v = _lastValue.remove(key) as T?;
        if (v != null) {
          target?.call(v);
        }
      }
    });
  } else if (trailing) {
    _throttlePending[key] = true;
    _lastValue[key] = value;
  }
}