ThrottleStreamTransformer<T> constructor

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

Construct a StreamTransformer that 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.

Implementation

ThrottleStreamTransformer(
  Stream<void> Function(T event) window, {
  bool trailing = false,
  bool leading = true,
}) : super(
        WindowStrategy.eventAfterLastWindow,
        window,
        onWindowStart: leading ? (event) => event : null,
        onWindowEnd: trailing ? (queue) => queue.last : null,
        dispatchOnClose: trailing,
        maxLengthQueue: trailing ? 2 : 0,
      );