throttle function

Function throttle(
  1. int ms,
  2. Function target,
  3. List arguments
)

The function is called at most once in a specified time period the function is called with the latest arguments

Implementation

Function throttle(int ms, Function target, List arguments) {
  var last = 0;
  return () {
    var now = DateTime.now().millisecondsSinceEpoch;
    if (now - last > ms) {
      last = now;
      Function.apply(target, arguments);
    }
  };
}