throttle method

Stream<T> throttle(
  1. Stream<void> window(
    1. T event
    ), {
  2. bool trailing = false,
  3. bool leading = true,
})

Emits a value from the source Stream, then ignores subsequent source values while the window Stream is open, then repeats this process.

If leading is true, then the first item in each window is emitted. If trailing is true, then the last item in each window is emitted.

You can use the value of the last throttled event to determine the length of the next window.

Example

Stream.fromIterable([1, 2, 3])
  .throttle((_) => TimerStream(true, Duration(seconds: 1)));

Implementation

Stream<T> throttle(Stream<void> Function(T event) window,
        {bool trailing = false, bool leading = true}) =>
    ThrottleStreamTransformer<T>(
      window,
      trailing: trailing,
      leading: leading,
    ).bind(this);