throttle3 static method

dynamic throttle3(
  1. Function func, [
  2. int delay = 500
])

节流 (传入所要节流的方法/回调与延迟时间)

Implementation

static throttle3(Function func, [int delay = 500]) {
  Timer? timer;
  bool isExecuting = false;
  return () {
    if (isExecuting) return;
    isExecuting = true;
    timer?.cancel();
    timer = Timer(Duration(milliseconds: delay), () {
      func.call();
      isExecuting = false;
    });
  };
}