throttle method
Throttle value changes - callback is called at most once per duration
Implementation
void throttle(Duration duration, void Function(T value) callback) {
RxTimingUtils._register(this);
bool canCall = true;
void listener() {
if (isDisposed) return;
if (canCall) {
canCall = false;
callback(value); // Use current value, not previous
late Timer currentTimer;
currentTimer = Timer(duration, () {
RxTimingUtils._getTimingData(this)?.removeTimer(currentTimer);
canCall = true;
});
// Track the timer for cleanup
RxTimingUtils._getTimingData(this)?.addTimer(currentTimer);
}
}
addListener(listener);
}