throttle1<T> method

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

Implementation

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