throttle2 static method

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

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

Implementation

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