throttleTime method

ReactiveSubject<T> throttleTime(
  1. Duration duration
)

Emits the first item emitted by the source ReactiveSubject in each time window of a specified duration.

Usage:

final subject = ReactiveSubject<int>();
final throttled = subject.throttleTime(Duration(seconds: 1));
throttled.stream.listen(print);
subject.add(1); // Prints: 1
subject.add(2);
subject.add(3); // After 1 second, prints: 3

Implementation

ReactiveSubject<T> throttleTime(Duration duration) {
  final result = ReactiveSubject<T>();
  stream.throttleTime(duration).listen(result.add, onError: result.addError);
  return result;
}