throttle2<T, E> method

void Function(T t, E e) throttle2<T, E>({
  1. int milliseconds = 500,
})

Implementation

void Function(T t, E e) throttle2<T, E>({int milliseconds = 500}) {
  var isAllowed = true;
  Timer? throttleTimer;
  return (t, e) {
    if (!isAllowed) return;
    isAllowed = false;
    this(t,e);
    throttleTimer?.cancel();
    throttleTimer = Timer(Duration(milliseconds: milliseconds), () {
      isAllowed = true;
    });
  };
}