interval<T> method

void interval<T>(
  1. RxVar<T> rx,
  2. void worker(
    1. T
    ), {
  3. Duration duration = const Duration(milliseconds: 500),
  4. bool leading = true,
})

Implementation

void interval<T>(
  RxVar<T> rx,
  void Function(T) worker, {
  Duration duration = const Duration(milliseconds: 500),
  bool leading = true,
}) {
  // rxdart's debounceTime emits the *last* event after the duration has passed since the last event
  Stream<T> s = rx.stream.debounceTime(duration);

  // If leading is true, emit first value immediately and then throttle
  if (leading && rx.hasValue) {
    worker(rx.value);
  }

  addWorker(s.skip(1).listen(worker));
}