createDebounceFunc<T> static method

  1. @internal
dynamic Function(T) createDebounceFunc<T>(
  1. dynamic f(
    1. T
    ), {
  2. dynamic cancelFunc(
    1. Function
    )?,
  3. required Duration wait,
})

Implementation

@internal
static Function(T) createDebounceFunc<T>(
  Function(T) f, {
  Function(Function)? cancelFunc,
  required Duration wait,
}) {
  Timer? t;
  return (p) {
    t?.cancel();
    t = Timer(wait, () {
      t = null;
      f(p);
    });
    // pass back the cancel method so we can cancel it when no longer needed
    cancelFunc?.call(t!.cancel);
  };
}