throttle static method

ThrottledCallback throttle(
  1. void func(),
  2. Duration interval, {
  3. bool leading = true,
  4. bool trailing = false,
  5. ThrottlerErrorHandler? onError,
})

Creates a throttled callback that invokes func at most once per interval.

The returned object is callable like a function and supports cancel/dispose.

Implementation

static ThrottledCallback throttle(
  void Function() func,
  Duration interval, {
  bool leading = true,
  bool trailing = false,
  ThrottlerErrorHandler? onError,
}) {
  final throttler = Throttler(
    interval: interval,
    leading: leading,
    trailing: trailing,
    onError: onError,
  );
  return ThrottledCallback(throttler, func);
}