The Generics type `Function(T a)` is only allowed one paramter now. Not sure how to improve the type yet. ## Usage `$ dart ./main.dart` ``` 0 2 4 6 8 ``` main.dart ```dart import 'dart:async'; import './throttle.dart'; void main() async { var f = Throttle.create((int n) { print(n); }, duration: const Duration(milliseconds: 1000)); for (int i = 0; i < 10; i++) { f(i); await Future.delayed(Duration(milliseconds: 500)); } } ``` ## throttle.dart ```dart import 'dart:async'; typedef ThrottledFunction = Function(T a); class Throttle { Duration duration; Timer? _timer; ThrottledFunction? _throttledFunction; Throttle(this._throttledFunction, {this.duration = const Duration(milliseconds: 500)}); void call(T a) { if (_timer == null || !_timer!.isActive) { _timer = Timer(duration, () { _throttledFunction!(a); _timer = null; }); } } static Throttle create(ThrottledFunction function, {duration = const Duration(milliseconds: 500)}) { return Throttle(function, duration: duration); } } ```