ThrottledSignal<T> constructor

ThrottledSignal<T>(
  1. Signal<T> source,
  2. Duration duration, {
  3. String? debugLabel,
  4. bool equals(
    1. T a,
    2. T b
    )?,
  5. T guard(
    1. T current,
    2. T next
    )?,
  6. VoidCallback? onListen,
  7. VoidCallback? onCancel,
})

Implementation

ThrottledSignal(
  this.source,
  this.duration, {
  String? debugLabel,
  super.equals,
  super.guard,
  super.onListen,
  super.onCancel,
}) : super(source.val, debugLabel: debugLabel) {
  _subscription = source.stream.listen((value) {
    if (!_isThrottled) {
      emit(value);
      _isThrottled = true;
      _throttleTimer = Timer(duration, () {
        _isThrottled = false;
      });
    }
  });
}