throttle method

Stream<T> throttle(
  1. Duration duration
)

Implementation

Stream<T> throttle(Duration duration) {
  var lastEmit = DateTime.fromMillisecondsSinceEpoch(0);
  return where((_) {
    final now = DateTime.now();
    if (now.difference(lastEmit) >= duration) {
      lastEmit = now;
      return true;
    }
    return false;
  });
}