interval<T> method
void
interval<T>(
- RxInterface<
T> rx, - void callback(
- T
- Duration duration = const Duration(seconds: 1),
Calls callback at most once per duration, ignoring
intermediate changes. Useful for rate-limiting UI updates.
interval(scrollPosition, (pos) => loadMore(pos),
duration: const Duration(seconds: 1));
Implementation
void interval<T>(
RxInterface<T> rx,
void Function(T) callback, {
Duration duration = const Duration(seconds: 1),
}) {
bool canCall = true;
_workers.add(rx.listen((val) {
if (canCall) {
canCall = false;
callback(val);
Timer(duration, () => canCall = true);
}
}));
}