throttleTime method

Stream<T> throttleTime (
  1. Duration duration,
  2. {bool trailing: false}
)

Emits only the first item emitted by the source Stream within a time span of duration.

if trailing is true, then the last item is emitted instead

Example

Stream.fromIterable([1, 2, 3])
  .throttleTime(Duration(seconds: 1))

Implementation

Stream<T> throttleTime(Duration duration, {bool trailing = false}) {
  ArgumentError.checkNotNull(duration, 'duration');
  return transform(
    ThrottleStreamTransformer<T>(
      (_) => TimerStream<bool>(true, duration),
      trailing: trailing,
    ),
  );
}