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